]> git.sven.stormbind.net Git - sven/vym.git/blob - findwidget.cpp
a75184c2fccb8aee05930144c80c576a017555de
[sven/vym.git] / findwidget.cpp
1 #include <QAction>
2 #include <QDebug>
3 #include <QLineEdit>
4 #include <QVBoxLayout>
5 #include <QLabel>
6
7 #include <QComboBox>
8 #include <QPushButton>
9 #include <QGroupBox>
10 #include <QLabel>
11
12
13 #include "findwidget.h"
14 #include "mainwindow.h"
15
16
17 extern Main *mainWindow;
18
19 FindWidget::FindWidget(QWidget *)
20 {
21     QVBoxLayout* mainLayout = new QVBoxLayout;  
22     QHBoxLayout *row2Layout = new QHBoxLayout;
23     
24     QLabel *label=new QLabel;
25     label->setText (tr("Find:","FindWidget"));
26     
27     // Create LineEdit (here QComboBox)
28     findcombo = new QComboBox;
29     findcombo->setMinimumWidth(250);
30     findcombo->setEditable(true);
31
32     QSizePolicy sizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
33     findcombo->setSizePolicy(sizePolicy);
34     connect ( findcombo, SIGNAL( highlighted(int) ), 
35         this, SLOT( nextPressed() ) );
36     connect ( findcombo, SIGNAL( editTextChanged(const QString &) ), 
37         this, SLOT( findTextChanged(const QString&) ) );
38
39     nextbutton = new QPushButton;
40     nextbutton->setIcon (QPixmap(":/find.png"));
41     //nextbutton->setText (tr("Find","Find widget"));
42     connect ( nextbutton, SIGNAL( clicked() ), this, SLOT( nextPressed() ) );
43
44     // QAction needed to only activate shortcut while FindWidget has focus
45     QAction *a=new QAction (nextbutton->text(),this);
46     a->setShortcut (Qt::Key_Return);
47     a->setShortcutContext (Qt::WidgetWithChildrenShortcut);
48     connect ( a, SIGNAL( triggered() ), this, SLOT( nextPressed() ) );
49     addAction (a);
50
51     row2Layout->addWidget (label);
52     row2Layout->addWidget(findcombo);
53     row2Layout->addWidget(nextbutton);
54
55     mainLayout->addLayout (row2Layout);
56
57     setLayout (mainLayout);
58     status=Undefined;
59 }
60
61 QString FindWidget::getFindText()
62 {
63     return findcombo->currentText();
64 }
65
66 void FindWidget::cancelPressed()
67 {
68     hide();
69     emit (hideFindWidget() );//Restore focus
70 }
71
72 void FindWidget::nextPressed()
73 {
74     emit (nextButton(findcombo->currentText() ) );
75 }
76
77 void FindWidget::findTextChanged(const QString&)
78 {
79     setStatus (Undefined);
80 }
81
82 void FindWidget::setFocus()
83 {
84     findcombo->lineEdit()->selectAll();
85     findcombo->lineEdit()->setFocus();
86 }
87
88 void FindWidget::setStatus (Status st)
89 {
90     if (st==status) return;
91
92     status=st;
93     QPalette p=palette();
94     QColor c;
95     switch (st)
96     {
97         case Success: c=QColor (120,255,120); break;
98         case Failed:  c=QColor (255,120,120); break;
99         default:  c=QColor (255,255,255); 
100     }
101     p.setColor(QPalette::Active, static_cast<QPalette::ColorRole>(9), c);
102     p.setColor(QPalette::Inactive, static_cast<QPalette::ColorRole>(9), c);
103     findcombo->setPalette(p);
104 }
105