PageRenderTime 45ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/xivoclient/src/xletlib/extendedtablewidget.cpp

https://gitlab.com/xivo.solutions/xivo-client-qt
C++ | 97 lines | 60 code | 9 blank | 28 comment | 8 complexity | cc5ac756b070b29993bf6343e648a88e MD5 | raw file
  1. /* XiVO Client
  2. * Copyright (C) 2007-2015 Avencall
  3. *
  4. * This file is part of XiVO Client.
  5. *
  6. * XiVO Client is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version, with a Section 7 Additional
  10. * Permission as follows:
  11. * This notice constitutes a grant of such permission as is necessary
  12. * to combine or link this software, or a modified version of it, with
  13. * the OpenSSL project's "OpenSSL" library, or a derivative work of it,
  14. * and to copy, modify, and distribute the resulting work. This is an
  15. * extension of the special permission given by Trolltech to link the
  16. * Qt code with the OpenSSL library (see
  17. * <http://doc.trolltech.com/4.4/gpl.html>). The OpenSSL library is
  18. * licensed under a dual license: the OpenSSL License and the original
  19. * SSLeay license.
  20. *
  21. * XiVO Client is distributed in the hope that it will be useful,
  22. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  23. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  24. * GNU General Public License for more details.
  25. *
  26. * You should have received a copy of the GNU General Public License
  27. * along with XiVO Client. If not, see <http://www.gnu.org/licenses/>.
  28. */
  29. #include <QDebug>
  30. #include <QMessageBox>
  31. #include <QHeaderView>
  32. #include <QMenu>
  33. #include <QAction>
  34. #include <xivoconsts.h>
  35. #include <storage/userinfo.h>
  36. #include <storage/phoneinfo.h>
  37. #include <baseengine.h>
  38. #include <phonenumber.h>
  39. #include "extendedtablewidget.h"
  40. ExtendedTableWidget::ExtendedTableWidget(QWidget * parent)
  41. : QTableWidget(parent)
  42. {
  43. setAlternatingRowColors(true);
  44. horizontalHeader()->setDefaultAlignment(Qt::AlignLeft);
  45. connect(horizontalHeader(),
  46. SIGNAL(sortIndicatorChanged(int, Qt::SortOrder)),
  47. SLOT(emitColumnSorted(int, Qt::SortOrder)));
  48. }
  49. void ExtendedTableWidget::contextMenuEvent(QContextMenuEvent * event)
  50. {
  51. QTableWidgetItem *item = itemAt(event->pos());
  52. QAction *action;
  53. if (item) {
  54. event->accept();
  55. QMenu contextMenu( this );
  56. if (PhoneNumber::phone_re().exactMatch(item->text())) {
  57. action = contextMenu.addAction(tr("&Dial"), this, SLOT(dialNumber()));
  58. action->setProperty("number", item->text());
  59. } else if(item->text().contains("@")) {
  60. action = contextMenu.addAction(tr("Send an E-mail"),
  61. this, SLOT(sendMail()) );
  62. action->setProperty("email", item->text());
  63. }
  64. if(!contextMenu.isEmpty()) {
  65. contextMenu.exec(event->globalPos());
  66. }
  67. } else {
  68. event->ignore();
  69. }
  70. }
  71. void ExtendedTableWidget::dialNumber()
  72. {
  73. QString number = sender()->property("number").toString();
  74. if (! number.isEmpty()) {
  75. b_engine->actionDial(number);
  76. }
  77. }
  78. void ExtendedTableWidget::sendMail()
  79. {
  80. QString email = sender()->property("email").toString();
  81. if (!email.isEmpty()) {
  82. QDesktopServices::openUrl(QUrl("mailto:" + email));
  83. }
  84. }
  85. void ExtendedTableWidget::emitColumnSorted(int column, Qt::SortOrder order)
  86. {
  87. emit columnSorted(column, order);
  88. }