13 #include "findwidget.h"
14 #include "mainwindow.h"
17 extern QString iconPath;
18 extern Main *mainWindow;
20 FindWidget::FindWidget(QWidget *)
22 QVBoxLayout* mainLayout = new QVBoxLayout;
23 QHBoxLayout *row2Layout = new QHBoxLayout;
26 cancelbutton = new QPushButton;
27 //cancelbutton->setText(tr("Cancel"));
28 cancelbutton->setIcon (QIcon (iconPath+"fileclose.png"));
29 cancelbutton->setShortcut (Qt::Key_Escape);
30 connect ( cancelbutton, SIGNAL( clicked() ), this, SLOT( cancelPressed() ) );
32 QLabel *label=new QLabel;
33 label->setText (tr("Find:","FindWidget"));
35 // Create LineEdit (here QComboBox)
36 findcombo = new QComboBox;
37 findcombo->setMinimumWidth(250);
38 findcombo->setEditable(true);
40 QSizePolicy sizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
41 findcombo->setSizePolicy(sizePolicy);
42 connect ( findcombo, SIGNAL( highlighted(int) ),
43 this, SLOT( nextPressed() ) );
44 connect ( findcombo, SIGNAL( textChanged(const QString &) ),
45 this, SLOT( findTextChanged(const QString&) ) );
47 nextbutton = new QPushButton;
48 nextbutton->setText (tr("Next","Find widget"));
49 nextbutton->setDefault (true);
50 nextbutton->setShortcut (Qt::Key_Return);
51 connect ( nextbutton, SIGNAL( clicked() ), this, SLOT( nextPressed() ) );
53 showAllButton = new QPushButton;
54 showAllButton->setText (tr("Show all","Find widget"));
55 //connect ( showAllButton, SIGNAL( clicked() ), this, SLOT( showAllPressed() ) );
56 connect ( showAllButton, SIGNAL( clicked() ), mainWindow, SLOT( editOpenFindWidget() ) );
58 row2Layout->addWidget (cancelbutton);
59 row2Layout->addWidget (label);
60 row2Layout->addWidget(findcombo);
61 row2Layout->addWidget(nextbutton);
62 row2Layout->addWidget(showAllButton);
64 mainLayout->addLayout (row2Layout);
66 setLayout (mainLayout);
70 void FindWidget::popup()
73 findcombo->lineEdit()->selectAll();
74 findcombo->setFocus();
75 setStatus (Undefined);
78 void FindWidget::cancelPressed()
81 emit (hideFindWidget() );//Restore focus
84 void FindWidget::nextPressed()
86 emit (nextButton(findcombo->currentText() ) );
89 void FindWidget::findTextChanged(const QString&)
91 setStatus (Undefined);
94 void FindWidget::setFocus()
96 findcombo->setFocus();
99 void FindWidget::setStatus (Status st)
101 if (st==status) return;
104 QPalette p=palette();
108 case Success: c=QColor (120,255,120); break;
109 case Failed: c=QColor (255,120,120); break;
110 default: c=QColor (255,255,255);
112 p.setColor(QPalette::Active, static_cast<QPalette::ColorRole>(9), c);
113 p.setColor(QPalette::Inactive, static_cast<QPalette::ColorRole>(9), c);
114 findcombo->setPalette(p);