annotate src/findwidget.cpp @ 587:4ed384ea7f39 fswatcher

comment only
author Chris Cannam
date Wed, 14 Mar 2012 12:00:20 +0000
parents 1ff2a1bf0a40
children 51887087f1ae
rev   line source
Chris@556 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@556 2
Chris@556 3 /*
Chris@556 4 EasyMercurial
Chris@556 5
Chris@556 6 Based on HgExplorer by Jari Korhonen
Chris@556 7 Copyright (c) 2010 Jari Korhonen
Chris@560 8 Copyright (c) 2012 Chris Cannam
Chris@560 9 Copyright (c) 2012 Queen Mary, University of London
Chris@556 10
Chris@556 11 This program is free software; you can redistribute it and/or
Chris@556 12 modify it under the terms of the GNU General Public License as
Chris@556 13 published by the Free Software Foundation; either version 2 of the
Chris@556 14 License, or (at your option) any later version. See the file
Chris@556 15 COPYING included with this distribution for more information.
Chris@556 16 */
Chris@556 17
Chris@556 18 #include "findwidget.h"
Chris@556 19
Chris@556 20 #include <QGridLayout>
Chris@556 21 #include <QLabel>
Chris@556 22 #include <QLineEdit>
Chris@556 23 #include <QToolButton>
Chris@556 24
Chris@556 25 FindWidget::FindWidget(QWidget *parent) :
Chris@556 26 QWidget(parent)
Chris@556 27 {
Chris@556 28 QGridLayout *layout = new QGridLayout;
Chris@558 29 layout->setMargin(0);
Chris@556 30 setLayout(layout);
Chris@556 31
Chris@556 32 QToolButton *button = new QToolButton();
Chris@556 33 layout->addWidget(button, 0, 0);
Chris@556 34 button->setText(tr("Find..."));
Chris@556 35 button->setToolButtonStyle(Qt::ToolButtonTextOnly);
Chris@556 36 connect(button, SIGNAL(clicked()), this, SLOT(buttonPressed()));
Chris@556 37
Chris@556 38 m_lineEdit = new QLineEdit();
Chris@556 39 layout->addWidget(m_lineEdit, 0, 1);
Chris@556 40
Chris@556 41 m_lineEdit->setFixedWidth(100);
Chris@556 42 m_lineEdit->hide();
Chris@556 43
Chris@558 44 int h = m_lineEdit->sizeHint().height();
Chris@558 45 int h0 = button->sizeHint().height();
Chris@558 46 if (h > h0) button->setFixedHeight(h);
Chris@558 47
Chris@556 48 connect(m_lineEdit, SIGNAL(textChanged(const QString &)),
Chris@556 49 this, SIGNAL(findTextChanged(QString)));
Chris@556 50 }
Chris@556 51
Chris@556 52 FindWidget::~FindWidget()
Chris@556 53 {
Chris@556 54 }
Chris@556 55
Chris@556 56 void
Chris@556 57 FindWidget::buttonPressed()
Chris@556 58 {
Chris@556 59 QAbstractButton *button = qobject_cast<QAbstractButton *>(sender());
Chris@556 60 if (!button) return;
Chris@556 61 if (m_lineEdit->isVisible()) {
Chris@556 62 m_lineEdit->hide();
Chris@556 63 button->setText(tr("Find..."));
Chris@557 64 if (m_lineEdit->text() != "") {
Chris@557 65 emit findTextChanged("");
Chris@557 66 }
Chris@556 67 } else {
Chris@556 68 m_lineEdit->show();
Chris@558 69 m_lineEdit->setFocus(Qt::OtherFocusReason);
Chris@556 70 button->setText(tr("Find:"));
Chris@557 71 if (m_lineEdit->text() != "") {
Chris@557 72 emit findTextChanged(m_lineEdit->text());
Chris@557 73 }
Chris@556 74 }
Chris@556 75 }
Chris@556 76