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 connect ( nextbutton, SIGNAL( clicked() ), this, SLOT( nextPressed() ) );
51 // QAction needed to only activate shortcut while FindWidget has focus
52 QAction *a=new QAction (nextbutton->text(),this);
53 a->setShortcut (Qt::Key_Return);
54 a->setShortcutContext (Qt::WidgetWithChildrenShortcut);
55 connect ( a, SIGNAL( triggered() ), this, SLOT( nextPressed() ) );
58 showAllButton = new QPushButton;
59 showAllButton->setText (tr("Show all","Find widget"));
60 connect ( showAllButton, SIGNAL( clicked() ), mainWindow, SLOT( editOpenFindWidget() ) );
62 row2Layout->addWidget (cancelbutton);
63 row2Layout->addWidget (label);
64 row2Layout->addWidget(findcombo);
65 row2Layout->addWidget(nextbutton);
66 row2Layout->addWidget(showAllButton);
68 mainLayout->addLayout (row2Layout);
70 setLayout (mainLayout);
74 void FindWidget::popup()
77 findcombo->lineEdit()->selectAll();
78 findcombo->setFocus();
79 setStatus (Undefined);
82 void FindWidget::cancelPressed()
85 emit (hideFindWidget() );//Restore focus
88 void FindWidget::nextPressed()
90 emit (nextButton(findcombo->currentText() ) );
93 void FindWidget::findTextChanged(const QString&)
95 setStatus (Undefined);
98 void FindWidget::setFocus()
100 findcombo->setFocus();
103 void FindWidget::setStatus (Status st)
105 if (st==status) return;
108 QPalette p=palette();
112 case Success: c=QColor (120,255,120); break;
113 case Failed: c=QColor (255,120,120); break;
114 default: c=QColor (255,255,255);
116 p.setColor(QPalette::Active, static_cast<QPalette::ColorRole>(9), c);
117 p.setColor(QPalette::Inactive, static_cast<QPalette::ColorRole>(9), c);
118 findcombo->setPalette(p);