10 #include <QPushButton>
12 #include "findwidget.h"
13 #include "mainwindow.h"
15 extern Main *mainWindow;
16 extern bool usingDarkTheme;
18 FindWidget::FindWidget(QWidget *)
20 QVBoxLayout *mainLayout = new QVBoxLayout;
21 QHBoxLayout *row2Layout = new QHBoxLayout;
23 QLabel *label = new QLabel;
24 label->setText(tr("Find:", "FindWidget"));
26 // Create LineEdit (here QComboBox)
27 findcombo = new QComboBox;
28 findcombo->setMinimumWidth(250);
29 findcombo->setEditable(true);
31 QSizePolicy sizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
32 findcombo->setSizePolicy(sizePolicy);
33 connect(findcombo, SIGNAL(highlighted(int)), this, SLOT(nextPressed()));
34 connect(findcombo, SIGNAL(editTextChanged(const QString &)), this,
35 SLOT(findTextChanged(const QString &)));
37 nextButton = new QPushButton;
38 nextButton->setIcon(QPixmap(":/find.png"));
39 // nextButton->setText (tr("Find","Find widget"));
40 connect(nextButton, SIGNAL(clicked()), this, SLOT(nextPressed()));
42 // QAction needed to only activate shortcut while FindWidget has focus
43 QAction *a = new QAction(nextButton->text(), this);
44 a->setShortcut(Qt::Key_Return);
45 a->setShortcutContext(Qt::WidgetWithChildrenShortcut);
46 connect(a, SIGNAL(triggered()), this, SLOT(nextPressed()));
49 filterNotesButton = new QPushButton;
50 filterNotesButton->setIcon(QPixmap(":/flag-note.svg"));
51 filterNotesButton->setCheckable(true);
52 filterNotesButton->setChecked(true);
53 connect(filterNotesButton, SIGNAL(clicked()), this, SLOT(nextPressed()));
55 row2Layout->addWidget(label);
56 row2Layout->addWidget(findcombo);
57 row2Layout->addWidget(nextButton);
58 row2Layout->addWidget(filterNotesButton);
60 mainLayout->addLayout(row2Layout);
62 setLayout(mainLayout);
66 QString FindWidget::getFindText() { return findcombo->currentText(); }
68 void FindWidget::cancelPressed()
71 emit(hideFindWidget()); // Restore focus
74 void FindWidget::nextPressed()
76 emit(nextButtonPressed(findcombo->currentText(),
77 filterNotesButton->isChecked()));
80 void FindWidget::findTextChanged(const QString &) { setStatus(Undefined); }
82 void FindWidget::setFocus()
84 findcombo->lineEdit()->selectAll();
85 findcombo->lineEdit()->setFocus();
88 void FindWidget::setStatus(Status st)
94 QPalette p = palette();
99 c = QColor(0, 170, 0);
102 c = QColor(170, 0, 0);
105 c = p.color(QPalette::Base);
110 c = QColor(120, 255, 120);
113 c = QColor(255, 120, 120);
116 c = p.color(QPalette::Base);
118 p.setColor(QPalette::Active, static_cast<QPalette::ColorRole>(9), c);
119 p.setColor(QPalette::Inactive, static_cast<QPalette::ColorRole>(9), c);
120 findcombo->setPalette(p);