findwidget.cpp
author insilmaril
Tue, 09 Mar 2010 13:09:05 +0000
changeset 833 bfacef6f29c1
parent 829 832e96c9abb6
child 834 0fad394bc330
permissions -rw-r--r--
Bugfix: Previous checkin caused toggleScroll to fail
     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 QString iconPath;
    18 extern Main *mainWindow;
    19 
    20 FindWidget::FindWidget(QWidget *)
    21 {
    22     QVBoxLayout* mainLayout = new QVBoxLayout;
    23     QHBoxLayout *row2Layout = new QHBoxLayout;
    24     
    25 	// Create Buttons
    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() ) );
    31 	
    32 	QLabel *label=new QLabel;
    33 	label->setText (tr("Find:","FindWidget"));
    34 	
    35 	// Create LineEdit (here QComboBox)
    36     findcombo = new QComboBox;
    37 	findcombo->setMinimumWidth(250);
    38 	findcombo->setEditable(true);
    39 
    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&) ) );
    46 
    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() ) );
    52 
    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() ) );
    57 
    58 	row2Layout->addWidget (cancelbutton);
    59 	row2Layout->addWidget (label);
    60 	row2Layout->addWidget(findcombo);
    61 	row2Layout->addWidget(nextbutton);
    62 	row2Layout->addWidget(showAllButton);
    63 
    64 	mainLayout->addLayout (row2Layout);
    65 
    66 	setLayout (mainLayout);
    67 	status=Undefined;
    68 }
    69 
    70 void FindWidget::popup()
    71 {
    72 	show();
    73 	findcombo->lineEdit()->selectAll();
    74 	findcombo->setFocus();
    75 	setStatus (Undefined);
    76 }
    77 
    78 void FindWidget::cancelPressed()
    79 {
    80 	hide();
    81 	emit (hideFindWidget() );//Restore focus
    82 }
    83 
    84 void FindWidget::nextPressed()
    85 {
    86 	emit (nextButton(findcombo->currentText() ) );
    87 }
    88 
    89 void FindWidget::findTextChanged(const QString&)
    90 {
    91 	setStatus (Undefined);
    92 }
    93 
    94 void FindWidget::setFocus()
    95 {
    96 	findcombo->setFocus();
    97 }
    98 
    99 void FindWidget::setStatus (Status st)
   100 {
   101 	if (st==status) return;
   102 
   103 	status=st;
   104 	QPalette p=palette();
   105 	QColor c;
   106 	switch (st)
   107 	{
   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); 
   111 	}
   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);
   115 }
   116