Commit f72109a1 authored by Nikita Baryshnikov's avatar Nikita Baryshnikov

SearchResultWindow: move initialization of private class to its own

Change-Id: I7ae2e7ab8c19270991083a8fc24002549e7f53a3
Reviewed-by: default avatarEike Ziller <eike.ziller@theqtcompany.com>
parent c0a187a1
......@@ -41,6 +41,7 @@
#include <QAction>
#include <QComboBox>
#include <QCoreApplication>
#include <QDebug>
#include <QFont>
#include <QLabel>
......@@ -79,12 +80,16 @@ namespace Internal {
class SearchResultWindowPrivate : public QObject
{
Q_OBJECT
Q_DECLARE_TR_FUNCTIONS(Core::SearchResultWindow)
public:
SearchResultWindowPrivate(SearchResultWindow *window);
bool isSearchVisible() const;
int visibleSearchIndex() const;
SearchResultWindowPrivate(SearchResultWindow *window, QWidget *newSearchPanel);
bool isSearchVisible() const { return m_currentIndex > 0; }
int visibleSearchIndex() const { return m_currentIndex - 1; }
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;
QList<Internal::SearchResultWidget *> m_searchResultWidgets;
......@@ -102,33 +107,47 @@ namespace Internal {
SearchResultColor m_color;
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),
m_expandCollapseButton(0),
m_expandCollapseAction(0),
m_spacer(0),
m_historyLabel(0),
m_spacer2(0),
m_recentSearchesBox(0),
m_widget(0),
m_expandCollapseAction(new QAction(tr("Expand All"), window)),
m_spacer(new QWidget),
m_historyLabel(new QLabel(tr("History:"))),
m_spacer2(new QWidget),
m_recentSearchesBox(new QComboBox),
m_widget(new QStackedWidget),
m_currentIndex(0),
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
{
return m_currentIndex > 0;
}
m_widget->setWindowTitle(q->displayName());
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)
......@@ -151,11 +170,6 @@ namespace Internal {
q->navigateStateChanged();
}
void SearchResultWindowPrivate::setCurrentIndex(int index)
{
setCurrentIndex(index, true/*focus*/);
}
void SearchResultWindowPrivate::moveWidgetToTop()
{
SearchResultWidget *widget = qobject_cast<SearchResultWidget *>(sender());
......@@ -283,41 +297,9 @@ SearchResultWindow *SearchResultWindow::m_instance = 0;
\internal
*/
SearchResultWindow::SearchResultWindow(QWidget *newSearchPanel)
: d(new SearchResultWindowPrivate(this))
: d(new SearchResultWindowPrivate(this, newSearchPanel))
{
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();
}
......@@ -424,7 +406,7 @@ SearchResult *SearchResultWindow::startNewSearch(const QString &label,
d->m_recentSearchesBox->insertItem(1, tr("%1 %2").arg(label, searchTerm));
if (d->m_currentIndex > 0)
++d->m_currentIndex; // so setCurrentIndex still knows about the right "currentIndex" and its widget
d->setCurrentIndex(1);
d->setCurrentIndexWithFocus(1);
return result;
}
......@@ -513,24 +495,21 @@ void SearchResultWindow::setTabWidth(int tabWidth)
void SearchResultWindow::openNewSearchPanel()
{
d->setCurrentIndex(0);
d->setCurrentIndexWithFocus(0);
popup(IOutputPane::ModeSwitch | IOutputPane::WithFocus | IOutputPane::EnsureSizeHint);
}
/*!
\internal
*/
void SearchResultWindow::handleExpandCollapseToolButton(bool checked)
void SearchResultWindowPrivate::handleExpandCollapseToolButton(bool checked)
{
if (!d->isSearchVisible())
if (!isSearchVisible())
return;
d->m_searchResultWidgets.at(d->visibleSearchIndex())->setAutoExpandResults(checked);
m_searchResultWidgets.at(visibleSearchIndex())->setAutoExpandResults(checked);
if (checked) {
d->m_expandCollapseAction->setText(tr("Collapse All"));
d->m_searchResultWidgets.at(d->visibleSearchIndex())->expandAll();
m_expandCollapseAction->setText(tr("Collapse All"));
m_searchResultWidgets.at(visibleSearchIndex())->expandAll();
} else {
d->m_expandCollapseAction->setText(tr("Expand All"));
d->m_searchResultWidgets.at(d->visibleSearchIndex())->collapseAll();
m_expandCollapseAction->setText(tr("Expand All"));
m_searchResultWidgets.at(visibleSearchIndex())->collapseAll();
}
}
......
......@@ -186,9 +186,6 @@ public:
public slots:
void clearContents();
private slots:
void handleExpandCollapseToolButton(bool checked);
public: // Used by plugin, do not use
void writeSettings();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment