1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185
|
/*
* Copyright (C) 2010 Nicolas Bonnefon and other contributors
*
* This file is part of glogg.
*
* glogg is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* glogg is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with glogg. If not, see <http://www.gnu.org/licenses/>.
*/
#include "log.h"
#include "configuration.h"
#include "quickfindwidget.h"
const int QuickFindWidget::NOTIFICATION_TIMEOUT = 5000;
QuickFindWidget::QuickFindWidget( QWidget* parent ) : QWidget( parent )
{
// ui_.setupUi( this );
// setFocusProxy(ui_.findEdit);
// setProperty("topBorder", true);
QHBoxLayout *layout = new QHBoxLayout( this );
layout->setMargin( 0 );
layout->setSpacing( 6 );
closeButton_ = setupToolButton(
QLatin1String(""), QLatin1String( ":/images/darkclosebutton.png" ) );
layout->addWidget( closeButton_ );
connect( closeButton_, SIGNAL( clicked() ), SLOT( closeHandler() ) );
editQuickFind_ = new QLineEdit( this );
// FIXME: set MinimumSize might be to constraining
editQuickFind_->setMinimumSize( QSize( 150, 0 ) );
layout->addWidget( editQuickFind_ );
/*
connect( editQuickFind_. SIGNAL( textChanged( QString ) ), this,
SLOT( textChanged( QString ) ) );
connect( editQuickFind_. SIGNAL( textChanged( QString ) ), this,
SLOT( updateButtons() ) );
*/
connect( editQuickFind_, SIGNAL( returnPressed() ),
this, SLOT( returnHandler() ) );
previousButton_ = setupToolButton( QLatin1String("Previous"),
QLatin1String( ":/images/arrowup.png" ) );
layout->addWidget( previousButton_ );
connect( previousButton_, SIGNAL( clicked() ),
this, SLOT( doSearchBackward() ) );
nextButton_ = setupToolButton( QLatin1String("Next"),
QLatin1String( ":/images/arrowdown.png" ) );
layout->addWidget( nextButton_ );
connect( nextButton_, SIGNAL( clicked() ),
this, SLOT( doSearchForward() ) );
notificationText_ = new QLabel( "" );
// FIXME: set MinimumSize might be to constraining
notificationText_->setMinimumSize( QSize( 150, 0 ) );
layout->addWidget( notificationText_ );
#if 0
QSpacerItem* spacerItem = new QSpacerItem(20, 20, QSizePolicy::Expanding,
QSizePolicy::Minimum);
layout_->addItem(spacerItem);
#endif
setMinimumWidth( minimumSizeHint().width() );
// Notification timer:
notificationTimer_ = new QTimer( this );
notificationTimer_->setSingleShot( true );
connect( notificationTimer_, SIGNAL( timeout() ),
this, SLOT( notificationTimeout() ) );
}
void QuickFindWidget::userActivate( QFDirection direction )
{
direction_ = direction;
userRequested_ = true;
QWidget::show();
editQuickFind_->setFocus( Qt::ShortcutFocusReason );
}
//
// SLOTS
//
void QuickFindWidget::changeDisplayedPattern( const QString& newPattern )
{
editQuickFind_->setText( newPattern );
}
void QuickFindWidget::notify( const QString& message )
{
LOG(logDEBUG) << "QuickFindWidget::notify()";
notificationText_->setText( message );
QWidget::show();
notificationTimer_->start( NOTIFICATION_TIMEOUT );
}
void QuickFindWidget::clearNotification()
{
LOG(logDEBUG) << "QuickFindWidget::clearNotification()";
notificationText_->setText( "" );
}
// User clicks forward arrow
void QuickFindWidget::doSearchForward()
{
LOG(logDEBUG) << "QuickFindWidget::doSearchForward()";
// The user has clicked on a button, so we assume she wants
// the widget to stay visible.
userRequested_ = true;
emit patternConfirmed( editQuickFind_->text() );
emit searchForward();
}
// User clicks backward arrow
void QuickFindWidget::doSearchBackward()
{
LOG(logDEBUG) << "QuickFindWidget::doSearchBackward()";
// The user has clicked on a button, so we assume she wants
// the widget to stay visible.
userRequested_ = true;
emit patternConfirmed( editQuickFind_->text() );
emit searchBackward();
}
// Close and search when the user presses Return
void QuickFindWidget::returnHandler()
{
emit patternConfirmed( editQuickFind_->text() );
// Close the widget
userRequested_ = false;
this->hide();
emit close();
emit searchForward();
}
// Close and reset flag when the user clicks 'close'
void QuickFindWidget::closeHandler()
{
userRequested_ = false;
this->hide();
emit close();
}
void QuickFindWidget::notificationTimeout()
{
// We close the widget if the user hasn't explicitely requested it.
if ( userRequested_ == false )
this->hide();
}
//
// Private functions
//
QToolButton* QuickFindWidget::setupToolButton(const QString &text, const QString &icon)
{
QToolButton *toolButton = new QToolButton(this);
toolButton->setText(text);
toolButton->setAutoRaise(true);
toolButton->setIcon(QIcon(icon));
toolButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
return toolButton;
}
|