[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: branches/KDE/4.2/kdebase/workspace/krunner/interfaces/quicksand
From: Ryan P. Bitanga <rjpbitanga () yahoo ! com>
Date: 2009-01-22 15:29:25
Message-ID: 1232638165.656405.24010.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 915220 by rbitanga:
Backport quicksand bugfixes for showing text mode/restoring normal mode on reset
M +30 -2 qs_dialog.cpp
M +2 -0 qs_dialog.h
M +43 -27 qs_matchview.cpp
M +2 -1 qs_matchview.h
--- branches/KDE/4.2/kdebase/workspace/krunner/interfaces/quicksand/qs_dialog.cpp #915219:915220
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2006 by Aaron Seigo <aseigo@kde.org>
- * Copyright (C) 2007-2008 Ryan P. Bitanga <ryan.bitanga@gmail.com>
+ * Copyright (C) 2007-2009 Ryan P. Bitanga <ryan.bitanga@gmail.com>
* Copyright (C) 2008 by Davide Bettio <davide.bettio@kdemail.net>
*
* This program is free software; you can redistribute it and/or modify
@@ -108,6 +108,8 @@
connect(m_actionView, SIGNAL(itemActivated(MatchItem*)), this, SLOT(run(MatchItem*)));
m_matchView->setFocus();
+
+ m_newQuery = true;
}
QsDialog::~QsDialog()
@@ -145,6 +147,7 @@
m_matchView->showLoading();
}
m_runnerManager->launchQuery(query);
+ m_newQuery = true;
}
void QsDialog::run(MatchItem *item)
@@ -184,7 +187,28 @@
void QsDialog::setMatches(const QList<Plasma::QueryMatch> &matches)
{
QList<MatchItem*> items;
+ QMultiMap<QString, Plasma::QueryMatch> temp;
+ QMultiMap<QString, Plasma::QueryMatch>::iterator end = m_matches.end();
foreach (Plasma::QueryMatch match, matches) {
+ temp.insert(match.id(), match);
+ // Do not create new MatchItems for existing matches when the query hasn't changed
+ if (!m_newQuery && m_matches.find(match.id()) != end) {
+ // kDebug() << "A match with id " << match.id() << " already exists." << endl;
+ QList<Plasma::QueryMatch> duplicates = m_matches.values(match.id());
+ bool exists = false;
+ foreach (Plasma::QueryMatch m, duplicates) {
+ // FIXME: Matching the displayed text isn't always reliable
+ // maybe adding an operator== to QueryMatch would help
+ if (m.text() == match.text()) {
+ exists = true;
+ break;
+ }
+ }
+
+ if (exists) {
+ continue;
+ }
+ }
MatchItem *m = new QuickSand::QueryMatchItem(match);
switch(match.type())
{
@@ -201,7 +225,11 @@
}
items.append(m);
}
- m_matchView->setItems(items);
+ // kDebug() << "Add " << items.size() << " matches. Append?" << !m_newQuery << endl;
+ m_matchView->setItems(items, true, !m_newQuery);
+ m_matches = temp;
+ // If new matches are obtained for the same query, append them to the list
+ m_newQuery = false;
}
void QsDialog::setAction(MatchItem *item)
--- branches/KDE/4.2/kdebase/workspace/krunner/interfaces/quicksand/qs_dialog.h #915219:915220
@@ -58,6 +58,8 @@
void loadActions(MatchItem *item);
void setAction(MatchItem *item);
private:
+ bool m_newQuery;
+ QMultiMap<QString, Plasma::QueryMatch> m_matches;
QuickSand::QsMatchView *m_matchView;
QuickSand::QsMatchView *m_actionView;
QuickSand::QueryMatchItem *m_currentMatch;
--- branches/KDE/4.2/kdebase/workspace/krunner/interfaces/quicksand/qs_matchview.cpp #915219:915220
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2007-2008 Ryan P. Bitanga <ryan.bitanga@gmail.com>
+ * Copyright (C) 2007-2009 Ryan P. Bitanga <ryan.bitanga@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -74,6 +74,7 @@
bool m_hasFocus;
bool m_itemsRemoved;
bool m_listVisible;
+ bool m_selectionMade;
};
QsMatchView::QsMatchView(QWidget *parent)
@@ -85,6 +86,7 @@
d->m_hasFocus = false;
d->m_itemsRemoved = false;
d->m_listVisible = true;
+ d->m_selectionMade = false; //Prevent completion box from popping up once a user chooses a match
//FIXME: don't hardcode black
setStyleSheet("QListWidget {color: black} QLineEdit {color: black}");
@@ -157,8 +159,10 @@
{
clear(true);
+ d->m_stack->setCurrentIndex(0);
d->m_arrowButton->hide();
d->m_listVisible = true;
+ d->m_selectionMade = false;
d->m_hasFocus = false;
d->m_searchTerm = QString();
d->m_compBox->clear();
@@ -172,26 +176,35 @@
setDescriptionText(i18n("Type to search."));
}
-void QsMatchView::setItems(const QList<MatchItem*> &items, bool popup)
+void QsMatchView::setItems(const QList<MatchItem*> &items, bool popup, bool append)
{
+ int spacing = MatchItem::ITEM_SIZE/2;
- clear(true);
+ int pos = spacing;
- d->m_compBox->clear();
+ if (!append) {
+ clear(true);
+ d->m_compBox->clear();
- d->m_currentItem = -1;
- d->m_items = items;
+ d->m_currentItem = -1;
+ d->m_items = items;
+ } else {
+ // FIXME: This completely disregards item ranking
+ // Maybe should we just sort then scroll to previously selected item
+ if (!d->m_items.isEmpty()) {
+ pos += d->m_items.last()->pos().x();
+ }
+ d->m_items << items;
+ }
- int spacing = MatchItem::ITEM_SIZE/2;
-
- int pos = spacing;
-
- foreach(MatchItem *item, d->m_items) {
+ foreach(MatchItem *item, items) {
if (item) {
item->setPos(pos, SMALL_ICON_PADDING);
item->scale(0.5, 0.5);
pos += spacing;
- d->m_scene->addItem(item);
+ if (d->m_listVisible) {
+ d->m_scene->addItem(item);
+ }
QString description;
if (item->description().isEmpty()) {
description = item->name();
@@ -204,7 +217,14 @@
}
d->m_itemsRemoved = false;
setItemCount(d->m_items.size());
+
+ if (d->m_selectionMade) {
+ //kDebug() << "A user selection was already made" << endl;
+ return;
+ }
+
scrollToItem(0);
+
//Ensure popup is shown if desired
if (popup) {
if (items.size()) {
@@ -262,7 +282,11 @@
d->m_descRect->setBrush(b);
d->m_descRect->setPen(p);
- d->m_descText = new QGraphicsTextItem(text, d->m_descRect);
+ QFontMetrics fm(font());
+
+ // Show ellipsis in the middle to distinguish between strings with identical
+ // beginnings e.g. paths
+ d->m_descText = new QGraphicsTextItem(fm.elidedText(text, Qt::ElideMiddle, WIDTH), d->m_descRect);
//Center text
d->m_descText->setPos(-(d->m_descText->boundingRect().width()/2), 60);
@@ -306,11 +330,6 @@
void QsMatchView::showLoading()
{
clear(true);
-// QPointF pos[8];
-// for (int i = 0; i < 8; ++i) {
-// pos[i] = QPointF(std::sin((i * 6.28) / 8.0) * 25,
-// std::cos((i * 6.28) / 8.0) * 25);
-// }
d->m_descText = new QGraphicsTextItem(i18n("Loading..."), d->m_descRect);
d->m_descText->setDefaultTextColor(QColor(Qt::white));
@@ -319,14 +338,6 @@
//Center text
d->m_descText->setPos(-(d->m_descText->boundingRect().width()/2), (HEIGHT - fm.height())/2);
d->m_scene->addItem(d->m_descText);
-
-// for (int i = 0; i < 8; ++i) {
-// QGraphicsEllipseItem *item = new QGraphicsEllipseItem(0, 30, 6, 6);
-// item->setPos(pos[i]);
-// QBrush b(QColor(0, 0, 0, 255*i/8));
-// item->setBrush(b);
-// d->m_scene->addItem(item);
-// }
}
void QsMatchView::showList()
@@ -352,7 +363,9 @@
void QsMatchView::showSelected()
{
if (!d->m_items.size()) {
- reset();
+ if (d->m_searchTerm.isEmpty()) {
+ reset();
+ }
return;
}
@@ -573,6 +586,7 @@
QWidget::keyPressEvent(e);
return;
}
+
switch (e->key()) {
case Qt::Key_Period:
//Switch to line edit
@@ -606,6 +620,7 @@
&& d->m_currentItem < d->m_items.size()) {
emit itemActivated(d->m_items[d->m_currentItem]);
}
+ d->m_selectionMade = true;
showSelected();
return;
default:
@@ -620,6 +635,7 @@
} else {
d->m_searchTerm += c;
}
+ d->m_selectionMade = false;
}
}
d->m_lineEdit->setText(d->m_searchTerm);
--- branches/KDE/4.2/kdebase/workspace/krunner/interfaces/quicksand/qs_matchview.h #915219:915220
@@ -65,8 +65,9 @@
* Sets the list of items to be displayed on screen
* @param items The list of items to display
* @param popup Display the popup completion box
+ * @param append Append items to the current list instead of replacing it
*/
- void setItems(const QList<MatchItem*> &items, bool popup = true);
+ void setItems(const QList<MatchItem*> &items, bool popup = true, bool append = false);
/**
* Sets the item count text on the upper right hand corner
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic