findwidget.cpp
author insilmaril
Mon, 08 Mar 2010 12:21:46 +0000
changeset 827 a591443f229c
parent 825 1ad892c1a709
child 829 832e96c9abb6
permissions -rw-r--r--
Added missing flag for Bugzilla
     1 #include <QLineEdit>
     2 #include <QVBoxLayout>
     3 #include <QLabel>
     4 
     5 #include <QComboBox>
     6 #include <QPushButton>
     7 #include <QGroupBox>
     8 #include <QLabel>
     9 
    10 
    11 #include "findwidget.h"
    12 
    13 
    14 extern QString iconPath;
    15 
    16 FindWidget::FindWidget(QWidget *)
    17 {
    18     QVBoxLayout* mainLayout = new QVBoxLayout;
    19     QHBoxLayout *row2Layout = new QHBoxLayout;
    20     
    21 	// Create Buttons
    22 	cancelbutton = new QPushButton;
    23 	//cancelbutton->setText(tr("Cancel"));
    24 	cancelbutton->setIcon (QIcon (iconPath+"fileclose.png"));
    25 	cancelbutton->setShortcut (Qt::Key_Escape);
    26 	connect ( cancelbutton, SIGNAL( clicked() ), this, SLOT( cancelPressed() ) );
    27 	
    28 	QLabel *label=new QLabel;
    29 	label->setText (tr("Find:","FindWidget"));
    30 	
    31 	// Create LineEdit (here QComboBox)
    32     findcombo = new QComboBox;
    33 	findcombo->setMinimumWidth(250);
    34 	findcombo->setEditable(true);
    35 
    36 	QSizePolicy sizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
    37     findcombo->setSizePolicy(sizePolicy);
    38 	connect ( findcombo, SIGNAL( highlighted(int) ), 
    39 		this, SLOT( nextPressed() ) );
    40 	connect ( findcombo, SIGNAL( textChanged(const QString &) ), 
    41 		this, SLOT( findTextChanged(const QString&) ) );
    42 
    43 	nextbutton = new QPushButton;
    44 	nextbutton->setText (tr("Next","Find widget"));
    45 	nextbutton->setDefault (true);
    46 	nextbutton->setShortcut (Qt::Key_Return);
    47 	//nextbutton->setShortcutContext (Qt::WidgetShortcut);
    48 	connect ( nextbutton, SIGNAL( clicked() ), this, SLOT( nextPressed() ) );
    49 
    50 	row2Layout->addWidget (cancelbutton);
    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 void FindWidget::popup()
    62 {
    63 	show();
    64 	findcombo->lineEdit()->selectAll();
    65 	findcombo->setFocus();
    66 	setStatus (Undefined);
    67 }
    68 
    69 void FindWidget::cancelPressed()
    70 {
    71 	hide();
    72 	emit (hideFindWidget() );
    73 }
    74 
    75 void FindWidget::nextPressed()
    76 {
    77 	emit (nextButton(findcombo->currentText() ) );
    78 }
    79 
    80 void FindWidget::findTextChanged(const QString&)
    81 {
    82 	setStatus (Undefined);
    83 }
    84 
    85 void FindWidget::setStatus (Status st)
    86 {
    87 	if (st==status) return;
    88 
    89 	status=st;
    90 	QPalette p=palette();
    91 	QColor c;
    92 	switch (st)
    93 	{
    94 		case Success: c=QColor (120,255,120); break;
    95 		case Failed:  c=QColor (255,120,120); break;
    96 		default:  c=QColor (255,255,255); 
    97 	}
    98     p.setColor(QPalette::Active, static_cast<QPalette::ColorRole>(9), c);
    99     p.setColor(QPalette::Inactive, static_cast<QPalette::ColorRole>(9), c);
   100     findcombo->setPalette(p);
   101 }
   102