PageRenderTime 59ms CodeModel.GetById 1ms RepoModel.GetById 1ms app.codeStats 0ms

/src/dialogs/about_dialog.cpp

https://gitlab.com/mattbas/Knotter
C++ | 131 lines | 86 code | 20 blank | 25 comment | 5 complexity | 9ed70ba88d44db52e18f82943f74bf0a MD5 | raw file
  1. /**
  2. \file
  3. \author Mattia Basaglia
  4. \section License
  5. This file is part of Knotter.
  6. Copyright (C) 2012-2020 Mattia Basaglia
  7. Knotter is free software: you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation, either version 3 of the License, or
  10. (at your option) any later version.
  11. Knotter is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. GNU General Public License for more details.
  15. You should have received a copy of the GNU General Public License
  16. along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #include "about_dialog.hpp"
  19. #include "resource_manager.hpp"
  20. #include <QDir>
  21. #include <QContextMenuEvent>
  22. #include <QClipboard>
  23. #include <QDesktopServices>
  24. #include <QUrl>
  25. About_Dialog::About_Dialog(QWidget *parent) :
  26. QDialog(parent)
  27. {
  28. setupUi(this);
  29. label_title->setText(QString("%1 %2").arg(resource_manager().program.name())
  30. .arg(resource_manager().program.version() ));
  31. label_icon->setPixmap(QIcon(resource_manager().program.data("img/icon-big.svg")).pixmap(64));
  32. setWindowTitle(tr("About %1").arg(resource_manager().program.name()));
  33. list_plugin_dirs->addItems(resource_manager().program.data_directories_unckecked("plugins"));
  34. list_data_dirs->addItems(resource_manager().program.data_directories_unckecked(""));
  35. text_settings_file->setText(resource_manager().settings.settings_file());
  36. text_witable_data_dir->setText(resource_manager().program.writable_data_directory(""));
  37. context_menu.addAction(QIcon::fromTheme("edit-copy"),"Copy directory name",
  38. this, SLOT(click_copy()));
  39. context_menu.addAction(QIcon::fromTheme("document-open"),"Open in file manager",
  40. this, SLOT(click_open()));
  41. }
  42. void About_Dialog::changeEvent(QEvent *e)
  43. {
  44. QDialog::changeEvent(e);
  45. switch (e->type()) {
  46. case QEvent::LanguageChange:
  47. retranslateUi(this);
  48. setWindowTitle(tr("About %1").arg(resource_manager().program.name()));
  49. break;
  50. default:
  51. break;
  52. }
  53. }
  54. void About_Dialog::on_button_qt_clicked()
  55. {
  56. QApplication::aboutQt();
  57. }
  58. void About_Dialog::contextmenu_line(QPoint pos)
  59. {
  60. QLineEdit* ed = static_cast<QLineEdit*>(sender());
  61. show_context_menu(ed->text(),ed->mapToGlobal(pos));
  62. }
  63. void About_Dialog::contextmenu_list(QPoint pos)
  64. {
  65. QListWidget* list = static_cast<QListWidget*>(sender());
  66. QListWidgetItem * it = list->itemAt(pos);
  67. if ( it )
  68. {
  69. show_context_menu(it->text(),list->mapToGlobal(pos));
  70. }
  71. }
  72. void About_Dialog::show_context_menu(QString file, QPoint pos)
  73. {
  74. clicked_entry = file;
  75. if ( !clicked_entry.isEmpty() )
  76. {
  77. QFileInfo finfo(clicked_entry);
  78. context_menu.actions()[0]->setText(tr("Copy directory name"));
  79. context_menu.actions()[1]->setText(tr("Open in file manager"));
  80. if ( finfo.exists() )
  81. {
  82. context_menu.actions()[1]->setEnabled(true);
  83. if ( finfo.isFile() )
  84. {
  85. context_menu.actions()[0]->setText(tr("Copy file name"));
  86. context_menu.actions()[1]->setText(tr("Open file"));
  87. }
  88. }
  89. else
  90. {
  91. context_menu.actions()[1]->setEnabled(false);
  92. }
  93. context_menu.popup(pos);
  94. }
  95. }
  96. void About_Dialog::click_copy()
  97. {
  98. QApplication::clipboard()->setText(clicked_entry);
  99. }
  100. void About_Dialog::click_open()
  101. {
  102. QDesktopServices::openUrl(QUrl("file:///"+clicked_entry));
  103. }