Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Zolotarev <deathbaba@gmail.com>2011-06-06 06:20:10 +0400
committerAlex Zolotarev <alex@maps.me>2015-09-23 01:19:15 +0300
commit6eb1705e08c6b1c9affe86e5ec5117650469bf13 (patch)
treec7e03af9af39f0065aea53740899b33e394b16fd /qt/search_panel.cpp
parentdd93eaae8ff1e70036004057b9ddc88301d5a5bd (diff)
[qt] Added search active indicator and clear text button
Diffstat (limited to 'qt/search_panel.cpp')
-rw-r--r--qt/search_panel.cpp53
1 files changed, 51 insertions, 2 deletions
diff --git a/qt/search_panel.cpp b/qt/search_panel.cpp
index 8c65edecf8..4a6b214e04 100644
--- a/qt/search_panel.cpp
+++ b/qt/search_panel.cpp
@@ -3,10 +3,13 @@
#include "../std/bind.hpp"
+#include <QtCore/QTimer>
#include <QtGui/QHeaderView>
#include <QtGui/QTableWidget>
#include <QtGui/QLineEdit>
#include <QtGui/QVBoxLayout>
+#include <QtGui/QHBoxLayout>
+#include <QtGui/QPushButton>
namespace qt
{
@@ -26,8 +29,18 @@ SearchPanel::SearchPanel(DrawWidget * drawWidget, QWidget * parent)
m_pTable->horizontalHeader()->setResizeMode(QHeaderView::ResizeToContents);
connect(m_pTable, SIGNAL(cellClicked(int,int)), this, SLOT(OnSearchPanelItemClicked(int,int)));
+ m_pClearButton = new QPushButton(this);
+ connect(m_pClearButton, SIGNAL(pressed()), this, SLOT(OnClearButton()));
+ m_pClearButton->setVisible(false);
+ m_pClearButton->setFocusPolicy(Qt::NoFocus);
+ m_pAnimationTimer = new QTimer(this);
+ connect(m_pAnimationTimer, SIGNAL(timeout()), this, SLOT(OnAnimationTimer()));
+
+ QHBoxLayout * horizontalLayout = new QHBoxLayout();
+ horizontalLayout->addWidget(m_pEditor);
+ horizontalLayout->addWidget(m_pClearButton);
QVBoxLayout * verticalLayout = new QVBoxLayout();
- verticalLayout->addWidget(m_pEditor);
+ verticalLayout->addLayout(horizontalLayout);
verticalLayout->addWidget(m_pTable);
setLayout(verticalLayout);
@@ -62,7 +75,7 @@ void SearchPanel::OnSearchResult(search::Result * result, int queryId)
if (queryId != m_queryId)
return;
- if (!result->GetString().empty()) // last element
+ if (!result->GetString().empty())
{
int const rowCount = m_pTable->rowCount();
m_pTable->setRowCount(rowCount + 1);
@@ -72,7 +85,12 @@ void SearchPanel::OnSearchResult(search::Result * result, int queryId)
m_results.push_back(result);
}
else
+ { // last element
delete result;
+ // stop search busy indicator
+ m_pAnimationTimer->stop();
+ m_pClearButton->setIcon(QIcon(":/ui/x.png"));
+ }
}
void SearchPanel::OnSearchTextChanged(QString const & str)
@@ -85,8 +103,20 @@ void SearchPanel::OnSearchTextChanged(QString const & str)
QString const normalized = str.normalized(QString::NormalizationForm_KC);
if (!normalized.isEmpty())
+ {
m_pDrawWidget->Search(normalized.toUtf8().constData(),
bind(&SearchPanel::SearchResultThreadFunc, this, _1, m_queryId));
+ // show busy indicator
+ if (!m_pAnimationTimer->isActive())
+ m_pAnimationTimer->start(200);
+ OnAnimationTimer();
+ m_pClearButton->setFlat(true);
+ m_pClearButton->setVisible(true);
+ }
+ else
+ { // hide X button
+ m_pClearButton->setVisible(false);
+ }
}
void SearchPanel::OnSearchPanelItemClicked(int row, int)
@@ -122,4 +152,23 @@ void SearchPanel::OnViewportChanged()
OnSearchTextChanged(txt);
}
+void SearchPanel::OnAnimationTimer()
+{
+ static int angle = 0;
+ QPixmap pixmap(":/ui/busy.png");
+ QSize const oldSize = pixmap.size();
+ QMatrix rm;
+ angle += 15;
+ if (angle >= 360)
+ angle = 0;
+ rm.rotate(angle);
+ pixmap = pixmap.transformed(rm);
+ m_pClearButton->setIcon(QIcon(pixmap));
+}
+
+void SearchPanel::OnClearButton()
+{
+ m_pEditor->setText("");
+}
+
}