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