forked from qt-creator/qt-creator
SearchResultWindow: move initialization of private class to its own
Change-Id: I7ae2e7ab8c19270991083a8fc24002549e7f53a3 Reviewed-by: Eike Ziller <eike.ziller@theqtcompany.com>
This commit is contained in:
@@ -41,6 +41,7 @@
|
|||||||
|
|
||||||
#include <QAction>
|
#include <QAction>
|
||||||
#include <QComboBox>
|
#include <QComboBox>
|
||||||
|
#include <QCoreApplication>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QFont>
|
#include <QFont>
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
@@ -79,12 +80,16 @@ namespace Internal {
|
|||||||
|
|
||||||
class SearchResultWindowPrivate : public QObject
|
class SearchResultWindowPrivate : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_DECLARE_TR_FUNCTIONS(Core::SearchResultWindow)
|
||||||
public:
|
public:
|
||||||
SearchResultWindowPrivate(SearchResultWindow *window);
|
SearchResultWindowPrivate(SearchResultWindow *window, QWidget *newSearchPanel);
|
||||||
bool isSearchVisible() const;
|
bool isSearchVisible() const { return m_currentIndex > 0; }
|
||||||
int visibleSearchIndex() const;
|
int visibleSearchIndex() const { return m_currentIndex - 1; }
|
||||||
void setCurrentIndex(int index, bool focus);
|
void setCurrentIndex(int index, bool focus);
|
||||||
|
void setCurrentIndexWithFocus(int index) { setCurrentIndex(index, true); }
|
||||||
|
void moveWidgetToTop();
|
||||||
|
void popupRequested(bool focus);
|
||||||
|
void handleExpandCollapseToolButton(bool checked);
|
||||||
|
|
||||||
SearchResultWindow *q;
|
SearchResultWindow *q;
|
||||||
QList<Internal::SearchResultWidget *> m_searchResultWidgets;
|
QList<Internal::SearchResultWidget *> m_searchResultWidgets;
|
||||||
@@ -102,33 +107,47 @@ namespace Internal {
|
|||||||
SearchResultColor m_color;
|
SearchResultColor m_color;
|
||||||
int m_tabWidth;
|
int m_tabWidth;
|
||||||
|
|
||||||
public slots:
|
|
||||||
void setCurrentIndex(int index);
|
|
||||||
void moveWidgetToTop();
|
|
||||||
void popupRequested(bool focus);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
SearchResultWindowPrivate::SearchResultWindowPrivate(SearchResultWindow *window) :
|
SearchResultWindowPrivate::SearchResultWindowPrivate(SearchResultWindow *window, QWidget *nsp) :
|
||||||
q(window),
|
q(window),
|
||||||
m_expandCollapseButton(0),
|
m_expandCollapseButton(0),
|
||||||
m_expandCollapseAction(0),
|
m_expandCollapseAction(new QAction(tr("Expand All"), window)),
|
||||||
m_spacer(0),
|
m_spacer(new QWidget),
|
||||||
m_historyLabel(0),
|
m_historyLabel(new QLabel(tr("History:"))),
|
||||||
m_spacer2(0),
|
m_spacer2(new QWidget),
|
||||||
m_recentSearchesBox(0),
|
m_recentSearchesBox(new QComboBox),
|
||||||
m_widget(0),
|
m_widget(new QStackedWidget),
|
||||||
|
m_currentIndex(0),
|
||||||
m_tabWidth(8)
|
m_tabWidth(8)
|
||||||
{
|
{
|
||||||
}
|
m_spacer->setMinimumWidth(30);
|
||||||
|
m_spacer2->setMinimumWidth(5);
|
||||||
|
m_recentSearchesBox->setProperty("drawleftborder", true);
|
||||||
|
m_recentSearchesBox->setSizeAdjustPolicy(QComboBox::AdjustToContents);
|
||||||
|
m_recentSearchesBox->addItem(tr("New Search"));
|
||||||
|
connect(m_recentSearchesBox, static_cast<void (QComboBox::*)(int)>(&QComboBox::activated),
|
||||||
|
this, &SearchResultWindowPrivate::setCurrentIndexWithFocus);
|
||||||
|
|
||||||
bool SearchResultWindowPrivate::isSearchVisible() const
|
m_widget->setWindowTitle(q->displayName());
|
||||||
{
|
|
||||||
return m_currentIndex > 0;
|
InternalScrollArea *newSearchArea = new InternalScrollArea(m_widget);
|
||||||
}
|
newSearchArea->setWidget(nsp);
|
||||||
|
newSearchArea->setFocusProxy(nsp);
|
||||||
|
m_widget->addWidget(newSearchArea);
|
||||||
|
|
||||||
|
m_expandCollapseButton = new QToolButton(m_widget);
|
||||||
|
m_expandCollapseButton->setAutoRaise(true);
|
||||||
|
|
||||||
|
m_expandCollapseAction->setCheckable(true);
|
||||||
|
m_expandCollapseAction->setIcon(QIcon(QLatin1String(":/find/images/expand.png")));
|
||||||
|
Command *cmd = ActionManager::registerAction(m_expandCollapseAction, "Find.ExpandAll");
|
||||||
|
cmd->setAttribute(Command::CA_UpdateText);
|
||||||
|
m_expandCollapseButton->setDefaultAction(cmd->action());
|
||||||
|
|
||||||
|
connect(m_expandCollapseAction, &QAction::toggled, this,
|
||||||
|
&SearchResultWindowPrivate::handleExpandCollapseToolButton);
|
||||||
|
|
||||||
int SearchResultWindowPrivate::visibleSearchIndex() const
|
|
||||||
{
|
|
||||||
return m_currentIndex - 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SearchResultWindowPrivate::setCurrentIndex(int index, bool focus)
|
void SearchResultWindowPrivate::setCurrentIndex(int index, bool focus)
|
||||||
@@ -151,11 +170,6 @@ namespace Internal {
|
|||||||
q->navigateStateChanged();
|
q->navigateStateChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SearchResultWindowPrivate::setCurrentIndex(int index)
|
|
||||||
{
|
|
||||||
setCurrentIndex(index, true/*focus*/);
|
|
||||||
}
|
|
||||||
|
|
||||||
void SearchResultWindowPrivate::moveWidgetToTop()
|
void SearchResultWindowPrivate::moveWidgetToTop()
|
||||||
{
|
{
|
||||||
SearchResultWidget *widget = qobject_cast<SearchResultWidget *>(sender());
|
SearchResultWidget *widget = qobject_cast<SearchResultWidget *>(sender());
|
||||||
@@ -283,41 +297,9 @@ SearchResultWindow *SearchResultWindow::m_instance = 0;
|
|||||||
\internal
|
\internal
|
||||||
*/
|
*/
|
||||||
SearchResultWindow::SearchResultWindow(QWidget *newSearchPanel)
|
SearchResultWindow::SearchResultWindow(QWidget *newSearchPanel)
|
||||||
: d(new SearchResultWindowPrivate(this))
|
: d(new SearchResultWindowPrivate(this, newSearchPanel))
|
||||||
{
|
{
|
||||||
m_instance = this;
|
m_instance = this;
|
||||||
|
|
||||||
d->m_spacer = new QWidget;
|
|
||||||
d->m_spacer->setMinimumWidth(30);
|
|
||||||
d->m_historyLabel = new QLabel(tr("History:"));
|
|
||||||
d->m_spacer2 = new QWidget;
|
|
||||||
d->m_spacer2->setMinimumWidth(5);
|
|
||||||
d->m_recentSearchesBox = new QComboBox;
|
|
||||||
d->m_recentSearchesBox->setProperty("drawleftborder", true);
|
|
||||||
d->m_recentSearchesBox->setSizeAdjustPolicy(QComboBox::AdjustToContents);
|
|
||||||
d->m_recentSearchesBox->addItem(tr("New Search"));
|
|
||||||
connect(d->m_recentSearchesBox, SIGNAL(activated(int)), d, SLOT(setCurrentIndex(int)));
|
|
||||||
|
|
||||||
d->m_widget = new QStackedWidget;
|
|
||||||
d->m_widget->setWindowTitle(displayName());
|
|
||||||
|
|
||||||
InternalScrollArea *newSearchArea = new InternalScrollArea(d->m_widget);
|
|
||||||
newSearchArea->setWidget(newSearchPanel);
|
|
||||||
newSearchArea->setFocusProxy(newSearchPanel);
|
|
||||||
d->m_widget->addWidget(newSearchArea);
|
|
||||||
d->m_currentIndex = 0;
|
|
||||||
|
|
||||||
d->m_expandCollapseButton = new QToolButton(d->m_widget);
|
|
||||||
d->m_expandCollapseButton->setAutoRaise(true);
|
|
||||||
|
|
||||||
d->m_expandCollapseAction = new QAction(tr("Expand All"), this);
|
|
||||||
d->m_expandCollapseAction->setCheckable(true);
|
|
||||||
d->m_expandCollapseAction->setIcon(QIcon(QLatin1String(":/find/images/expand.png")));
|
|
||||||
Command *cmd = ActionManager::registerAction( d->m_expandCollapseAction, "Find.ExpandAll");
|
|
||||||
cmd->setAttribute(Command::CA_UpdateText);
|
|
||||||
d->m_expandCollapseButton->setDefaultAction(cmd->action());
|
|
||||||
|
|
||||||
connect(d->m_expandCollapseAction, SIGNAL(toggled(bool)), this, SLOT(handleExpandCollapseToolButton(bool)));
|
|
||||||
readSettings();
|
readSettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -424,7 +406,7 @@ SearchResult *SearchResultWindow::startNewSearch(const QString &label,
|
|||||||
d->m_recentSearchesBox->insertItem(1, tr("%1 %2").arg(label, searchTerm));
|
d->m_recentSearchesBox->insertItem(1, tr("%1 %2").arg(label, searchTerm));
|
||||||
if (d->m_currentIndex > 0)
|
if (d->m_currentIndex > 0)
|
||||||
++d->m_currentIndex; // so setCurrentIndex still knows about the right "currentIndex" and its widget
|
++d->m_currentIndex; // so setCurrentIndex still knows about the right "currentIndex" and its widget
|
||||||
d->setCurrentIndex(1);
|
d->setCurrentIndexWithFocus(1);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -513,24 +495,21 @@ void SearchResultWindow::setTabWidth(int tabWidth)
|
|||||||
|
|
||||||
void SearchResultWindow::openNewSearchPanel()
|
void SearchResultWindow::openNewSearchPanel()
|
||||||
{
|
{
|
||||||
d->setCurrentIndex(0);
|
d->setCurrentIndexWithFocus(0);
|
||||||
popup(IOutputPane::ModeSwitch | IOutputPane::WithFocus | IOutputPane::EnsureSizeHint);
|
popup(IOutputPane::ModeSwitch | IOutputPane::WithFocus | IOutputPane::EnsureSizeHint);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
void SearchResultWindowPrivate::handleExpandCollapseToolButton(bool checked)
|
||||||
\internal
|
|
||||||
*/
|
|
||||||
void SearchResultWindow::handleExpandCollapseToolButton(bool checked)
|
|
||||||
{
|
{
|
||||||
if (!d->isSearchVisible())
|
if (!isSearchVisible())
|
||||||
return;
|
return;
|
||||||
d->m_searchResultWidgets.at(d->visibleSearchIndex())->setAutoExpandResults(checked);
|
m_searchResultWidgets.at(visibleSearchIndex())->setAutoExpandResults(checked);
|
||||||
if (checked) {
|
if (checked) {
|
||||||
d->m_expandCollapseAction->setText(tr("Collapse All"));
|
m_expandCollapseAction->setText(tr("Collapse All"));
|
||||||
d->m_searchResultWidgets.at(d->visibleSearchIndex())->expandAll();
|
m_searchResultWidgets.at(visibleSearchIndex())->expandAll();
|
||||||
} else {
|
} else {
|
||||||
d->m_expandCollapseAction->setText(tr("Expand All"));
|
m_expandCollapseAction->setText(tr("Expand All"));
|
||||||
d->m_searchResultWidgets.at(d->visibleSearchIndex())->collapseAll();
|
m_searchResultWidgets.at(visibleSearchIndex())->collapseAll();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -186,9 +186,6 @@ public:
|
|||||||
public slots:
|
public slots:
|
||||||
void clearContents();
|
void clearContents();
|
||||||
|
|
||||||
private slots:
|
|
||||||
void handleExpandCollapseToolButton(bool checked);
|
|
||||||
|
|
||||||
public: // Used by plugin, do not use
|
public: // Used by plugin, do not use
|
||||||
void writeSettings();
|
void writeSettings();
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user