findwidget.cpp
author insilmaril
Wed, 09 Jun 2010 13:14:08 +0000
changeset 847 43268373032d
parent 834 0fad394bc330
permissions -rw-r--r--
1.13.4 Various fixes
insilmaril@829
     1
#include <QAction>
insilmaril@829
     2
#include <QDebug>
insilmaril@808
     3
#include <QLineEdit>
insilmaril@808
     4
#include <QVBoxLayout>
insilmaril@808
     5
#include <QLabel>
insilmaril@808
     6
insilmaril@825
     7
#include <QComboBox>
insilmaril@825
     8
#include <QPushButton>
insilmaril@825
     9
#include <QGroupBox>
insilmaril@825
    10
#include <QLabel>
insilmaril@825
    11
insilmaril@825
    12
insilmaril@808
    13
#include "findwidget.h"
insilmaril@829
    14
#include "mainwindow.h"
insilmaril@808
    15
insilmaril@808
    16
insilmaril@811
    17
extern QString iconPath;
insilmaril@829
    18
extern Main *mainWindow;
insilmaril@808
    19
insilmaril@810
    20
FindWidget::FindWidget(QWidget *)
insilmaril@808
    21
{
insilmaril@808
    22
    QVBoxLayout* mainLayout = new QVBoxLayout;
insilmaril@808
    23
    QHBoxLayout *row2Layout = new QHBoxLayout;
insilmaril@808
    24
    
insilmaril@808
    25
	// Create Buttons
insilmaril@808
    26
	cancelbutton = new QPushButton;
insilmaril@811
    27
	//cancelbutton->setText(tr("Cancel"));
insilmaril@811
    28
	cancelbutton->setIcon (QIcon (iconPath+"fileclose.png"));
insilmaril@808
    29
	cancelbutton->setShortcut (Qt::Key_Escape);
insilmaril@808
    30
	connect ( cancelbutton, SIGNAL( clicked() ), this, SLOT( cancelPressed() ) );
insilmaril@808
    31
	
insilmaril@810
    32
	QLabel *label=new QLabel;
insilmaril@810
    33
	label->setText (tr("Find:","FindWidget"));
insilmaril@810
    34
	
insilmaril@808
    35
	// Create LineEdit (here QComboBox)
insilmaril@808
    36
    findcombo = new QComboBox;
insilmaril@808
    37
	findcombo->setMinimumWidth(250);
insilmaril@808
    38
	findcombo->setEditable(true);
insilmaril@811
    39
insilmaril@811
    40
	QSizePolicy sizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
insilmaril@811
    41
    findcombo->setSizePolicy(sizePolicy);
insilmaril@808
    42
	connect ( findcombo, SIGNAL( highlighted(int) ), 
insilmaril@808
    43
		this, SLOT( nextPressed() ) );
insilmaril@808
    44
	connect ( findcombo, SIGNAL( textChanged(const QString &) ), 
insilmaril@808
    45
		this, SLOT( findTextChanged(const QString&) ) );
insilmaril@808
    46
insilmaril@808
    47
	nextbutton = new QPushButton;
insilmaril@808
    48
	nextbutton->setText (tr("Next","Find widget"));
insilmaril@808
    49
	connect ( nextbutton, SIGNAL( clicked() ), this, SLOT( nextPressed() ) );
insilmaril@808
    50
insilmaril@834
    51
	// QAction needed to only activate shortcut while FindWidget has focus
insilmaril@834
    52
	QAction *a=new QAction (nextbutton->text(),this);
insilmaril@834
    53
	a->setShortcut (Qt::Key_Return);
insilmaril@834
    54
	a->setShortcutContext (Qt::WidgetWithChildrenShortcut);
insilmaril@834
    55
	connect ( a, SIGNAL( triggered() ), this, SLOT( nextPressed() ) );
insilmaril@834
    56
	addAction (a);
insilmaril@834
    57
insilmaril@829
    58
	showAllButton = new QPushButton;
insilmaril@829
    59
	showAllButton->setText (tr("Show all","Find widget"));
insilmaril@829
    60
	connect ( showAllButton, SIGNAL( clicked() ), mainWindow, SLOT( editOpenFindWidget() ) );
insilmaril@829
    61
insilmaril@808
    62
	row2Layout->addWidget (cancelbutton);
insilmaril@810
    63
	row2Layout->addWidget (label);
insilmaril@808
    64
	row2Layout->addWidget(findcombo);
insilmaril@808
    65
	row2Layout->addWidget(nextbutton);
insilmaril@829
    66
	row2Layout->addWidget(showAllButton);
insilmaril@808
    67
insilmaril@808
    68
	mainLayout->addLayout (row2Layout);
insilmaril@808
    69
insilmaril@808
    70
	setLayout (mainLayout);
insilmaril@811
    71
	status=Undefined;
insilmaril@808
    72
}
insilmaril@808
    73
insilmaril@808
    74
void FindWidget::popup()
insilmaril@808
    75
{
insilmaril@808
    76
	show();
insilmaril@808
    77
	findcombo->lineEdit()->selectAll();
insilmaril@808
    78
	findcombo->setFocus();
insilmaril@811
    79
	setStatus (Undefined);
insilmaril@808
    80
}
insilmaril@808
    81
insilmaril@808
    82
void FindWidget::cancelPressed()
insilmaril@808
    83
{
insilmaril@808
    84
	hide();
insilmaril@829
    85
	emit (hideFindWidget() );//Restore focus
insilmaril@808
    86
}
insilmaril@808
    87
insilmaril@808
    88
void FindWidget::nextPressed()
insilmaril@808
    89
{
insilmaril@808
    90
	emit (nextButton(findcombo->currentText() ) );
insilmaril@808
    91
}
insilmaril@808
    92
insilmaril@808
    93
void FindWidget::findTextChanged(const QString&)
insilmaril@808
    94
{
insilmaril@811
    95
	setStatus (Undefined);
insilmaril@808
    96
}
insilmaril@808
    97
insilmaril@829
    98
void FindWidget::setFocus()
insilmaril@829
    99
{
insilmaril@829
   100
	findcombo->setFocus();
insilmaril@829
   101
}
insilmaril@829
   102
insilmaril@810
   103
void FindWidget::setStatus (Status st)
insilmaril@810
   104
{
insilmaril@811
   105
	if (st==status) return;
insilmaril@811
   106
insilmaril@811
   107
	status=st;
insilmaril@810
   108
	QPalette p=palette();
insilmaril@810
   109
	QColor c;
insilmaril@810
   110
	switch (st)
insilmaril@810
   111
	{
insilmaril@811
   112
		case Success: c=QColor (120,255,120); break;
insilmaril@811
   113
		case Failed:  c=QColor (255,120,120); break;
insilmaril@810
   114
		default:  c=QColor (255,255,255); 
insilmaril@810
   115
	}
insilmaril@810
   116
    p.setColor(QPalette::Active, static_cast<QPalette::ColorRole>(9), c);
insilmaril@810
   117
    p.setColor(QPalette::Inactive, static_cast<QPalette::ColorRole>(9), c);
insilmaril@810
   118
    findcombo->setPalette(p);
insilmaril@810
   119
}
insilmaril@810
   120