annotate src/findwidget.cpp @ 558:d932ce55c364 find

Remove the single find widget from top, add one to each tab at the bottom instead. (Turns out you don't usually want to search for the same text in both types of widget.) Also provide sensible no-results text.
author Chris Cannam
date Mon, 27 Feb 2012 17:08:26 +0000
parents 57a7f95ef400
children 533519ebc0cb
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@556 8 Copyright (c) 2011 Chris Cannam
Chris@556 9 Copyright (c) 2011 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@558 36 // button->setAutoRaise(true);
Chris@556 37 connect(button, SIGNAL(clicked()), this, SLOT(buttonPressed()));
Chris@556 38
Chris@556 39 m_lineEdit = new QLineEdit();
Chris@556 40 layout->addWidget(m_lineEdit, 0, 1);
Chris@556 41
Chris@556 42 m_lineEdit->setFixedWidth(100);
Chris@556 43 m_lineEdit->hide();
Chris@556 44
Chris@558 45 int h = m_lineEdit->sizeHint().height();
Chris@558 46 int h0 = button->sizeHint().height();
Chris@558 47 if (h > h0) button->setFixedHeight(h);
Chris@558 48
Chris@556 49 connect(m_lineEdit, SIGNAL(textChanged(const QString &)),
Chris@556 50 this, SIGNAL(findTextChanged(QString)));
Chris@556 51 }
Chris@556 52
Chris@556 53 FindWidget::~FindWidget()
Chris@556 54 {
Chris@556 55 }
Chris@556 56
Chris@556 57 void
Chris@556 58 FindWidget::buttonPressed()
Chris@556 59 {
Chris@556 60 QAbstractButton *button = qobject_cast<QAbstractButton *>(sender());
Chris@556 61 if (!button) return;
Chris@556 62 if (m_lineEdit->isVisible()) {
Chris@556 63 m_lineEdit->hide();
Chris@556 64 button->setText(tr("Find..."));
Chris@557 65 if (m_lineEdit->text() != "") {
Chris@557 66 emit findTextChanged("");
Chris@557 67 }
Chris@556 68 } else {
Chris@556 69 m_lineEdit->show();
Chris@558 70 m_lineEdit->setFocus(Qt::OtherFocusReason);
Chris@556 71 button->setText(tr("Find:"));
Chris@557 72 if (m_lineEdit->text() != "") {
Chris@557 73 emit findTextChanged(m_lineEdit->text());
Chris@557 74 }
Chris@556 75 }
Chris@556 76 }
Chris@556 77