| 29 | #include <QMouseEvent> |
| 30 | |
| 31 | DirectorySortMenu::DirectorySortMenu(QWidget *parent) : |
| 32 | QWidget(parent), |
| 33 | ui(new Ui::DirectorySortMenu) |
| 34 | { |
| 35 | ui->setupUi(this); |
| 36 | |
| 37 | // Style |
| 38 | _textColor = ContextManager::theme()->getColor(ThemeManager::HIGHLIGHTED_BACKGROUND).name(); |
| 39 | _backgroundColor = ContextManager::theme()->getColor(ThemeManager::HIGHLIGHTED_TEXT).name(); |
| 40 | _hoveredBackgroundColor = ContextManager::theme()->getColor(ThemeManager::HIGHLIGHTED_TEXT, ThemeManager::HOVERED).name(); |
| 41 | ui->labelSort->setPixmap(ContextManager::theme()->getColoredSvg(":/icons/sort.svg", QSize(16, 16), ThemeManager::HIGHLIGHTED_BACKGROUND)); |
| 42 | this->setStyle(false); |
| 43 | |
| 44 | // Icon |
| 45 | _checkIcon.addPixmap(ContextManager::theme()->getColoredSvg(":/icons/check.svg", QSize(24, 24), ThemeManager::LIST_TEXT), QIcon::Normal); |
| 46 | _checkIcon.addPixmap(ContextManager::theme()->getColoredSvg(":/icons/check.svg", QSize(24, 24), ThemeManager::HIGHLIGHTED_TEXT), QIcon::Active); |
| 47 | |
| 48 | // Add a menu to the button |
| 49 | int currentSort = ContextManager::configuration()->getValue(ConfManager::SECTION_DISPLAY, "directory_browser_sort", 0).toInt(); |
| 50 | if (currentSort < 0 || currentSort > 3) |
| 51 | currentSort = 0; |
| 52 | QMenu * menu = new QMenu(this); |
| 53 | connect(menu, SIGNAL(aboutToHide()), this, SLOT(onMenuClosed())); |
| 54 | menu->setStyleSheet(ContextManager::theme()->getMenuTheme()); |
| 55 | QAction * action = menu->addAction(tr("Name (A→Z)")); |
| 56 | if (currentSort == 0) |
| 57 | { |
| 58 | action->setIcon(_checkIcon); |
| 59 | ui->pushButton->setText(action->text()); |
| 60 | } |
| 61 | connect(action, SIGNAL(triggered()), this, SLOT(element1Clicked())); |
| 62 | action = menu->addAction(tr("Newest first")); |
| 63 | if (currentSort == 1) |
| 64 | { |
| 65 | action->setIcon(_checkIcon); |
| 66 | ui->pushButton->setText(action->text()); |
| 67 | } |
| 68 | connect(action, SIGNAL(triggered()), this, SLOT(element2Clicked())); |
| 69 | action = menu->addAction(tr("Largest first")); |
| 70 | if (currentSort == 2) |
| 71 | { |
| 72 | action->setIcon(_checkIcon); |
| 73 | ui->pushButton->setText(action->text()); |
| 74 | } |
| 75 | connect(action, SIGNAL(triggered()), this, SLOT(element3Clicked())); |
| 76 | action = menu->addAction(tr("Smallest first")); |
| 77 | if (currentSort == 3) |
| 78 | { |
| 79 | action->setIcon(_checkIcon); |
| 80 | ui->pushButton->setText(action->text()); |
| 81 | } |
| 82 | connect(action, SIGNAL(triggered()), this, SLOT(element4Clicked())); |
| 83 | ui->pushButton->setMenu(menu); |
| 84 | } |
| 85 | |
| 86 | DirectorySortMenu::~DirectorySortMenu() |
| 87 | { |
nothing calls this directly
no test coverage detected