Chris@556: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ Chris@556: Chris@556: /* Chris@556: EasyMercurial Chris@556: Chris@556: Based on HgExplorer by Jari Korhonen Chris@556: Copyright (c) 2010 Jari Korhonen Chris@556: Copyright (c) 2011 Chris Cannam Chris@556: Copyright (c) 2011 Queen Mary, University of London Chris@556: Chris@556: This program is free software; you can redistribute it and/or Chris@556: modify it under the terms of the GNU General Public License as Chris@556: published by the Free Software Foundation; either version 2 of the Chris@556: License, or (at your option) any later version. See the file Chris@556: COPYING included with this distribution for more information. Chris@556: */ Chris@556: Chris@556: #include "findwidget.h" Chris@556: Chris@556: #include Chris@556: #include Chris@556: #include Chris@556: #include Chris@556: Chris@556: FindWidget::FindWidget(QWidget *parent) : Chris@556: QWidget(parent) Chris@556: { Chris@556: QGridLayout *layout = new QGridLayout; Chris@558: layout->setMargin(0); Chris@556: setLayout(layout); Chris@556: Chris@556: QToolButton *button = new QToolButton(); Chris@556: layout->addWidget(button, 0, 0); Chris@556: button->setText(tr("Find...")); Chris@556: button->setToolButtonStyle(Qt::ToolButtonTextOnly); Chris@558: // button->setAutoRaise(true); Chris@556: connect(button, SIGNAL(clicked()), this, SLOT(buttonPressed())); Chris@556: Chris@556: m_lineEdit = new QLineEdit(); Chris@556: layout->addWidget(m_lineEdit, 0, 1); Chris@556: Chris@556: m_lineEdit->setFixedWidth(100); Chris@556: m_lineEdit->hide(); Chris@556: Chris@558: int h = m_lineEdit->sizeHint().height(); Chris@558: int h0 = button->sizeHint().height(); Chris@558: if (h > h0) button->setFixedHeight(h); Chris@558: Chris@556: connect(m_lineEdit, SIGNAL(textChanged(const QString &)), Chris@556: this, SIGNAL(findTextChanged(QString))); Chris@556: } Chris@556: Chris@556: FindWidget::~FindWidget() Chris@556: { Chris@556: } Chris@556: Chris@556: void Chris@556: FindWidget::buttonPressed() Chris@556: { Chris@556: QAbstractButton *button = qobject_cast(sender()); Chris@556: if (!button) return; Chris@556: if (m_lineEdit->isVisible()) { Chris@556: m_lineEdit->hide(); Chris@556: button->setText(tr("Find...")); Chris@557: if (m_lineEdit->text() != "") { Chris@557: emit findTextChanged(""); Chris@557: } Chris@556: } else { Chris@556: m_lineEdit->show(); Chris@558: m_lineEdit->setFocus(Qt::OtherFocusReason); Chris@556: button->setText(tr("Find:")); Chris@557: if (m_lineEdit->text() != "") { Chris@557: emit findTextChanged(m_lineEdit->text()); Chris@557: } Chris@556: } Chris@556: } Chris@556: