Hello community, here is the log from the commit of package libbaloowidgets for openSUSE:Factory checked in at 2014-07-16 16:19:10 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/libbaloowidgets (Old) and /work/SRC/openSUSE:Factory/.libbaloowidgets.new (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "libbaloowidgets" Changes: -------- --- /work/SRC/openSUSE:Factory/libbaloowidgets/libbaloowidgets.changes 2014-06-19 13:15:05.000000000 +0200 +++ /work/SRC/openSUSE:Factory/.libbaloowidgets.new/libbaloowidgets.changes 2014-07-16 16:20:12.000000000 +0200 @@ -1,0 +2,7 @@ +Thu Jul 10 22:16:07 UTC 2014 - [email protected] + +- Update to 4.13.80 + * KDE 4.14 Beta 1 release + * See http://www.kde.org/announcements/announce-4.14-beta1.php + +------------------------------------------------------------------- Old: ---- baloo-widgets-4.13.2.tar.xz New: ---- baloo-widgets-4.13.80.tar.xz ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ libbaloowidgets.spec ++++++ --- /var/tmp/diff_new_pack.RhMtla/_old 2014-07-16 16:20:12.000000000 +0200 +++ /var/tmp/diff_new_pack.RhMtla/_new 2014-07-16 16:20:12.000000000 +0200 @@ -19,7 +19,7 @@ %define rname baloo-widgets Name: libbaloowidgets -Version: 4.13.2 +Version: 4.13.80 Release: 0 Summary: Framework for searching and managing metadata License: GPL-2.0+ and LGPL-2.1+ ++++++ baloo-widgets-4.13.2.tar.xz -> baloo-widgets-4.13.80.tar.xz ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/baloo-widgets-4.13.2/src/CMakeLists.txt new/baloo-widgets-4.13.80/src/CMakeLists.txt --- old/baloo-widgets-4.13.2/src/CMakeLists.txt 2014-03-15 16:18:39.000000000 +0100 +++ new/baloo-widgets-4.13.80/src/CMakeLists.txt 2014-05-23 15:37:47.000000000 +0200 @@ -10,6 +10,9 @@ kcommentwidget.cpp metadatafilter.cpp widgetfactory.cpp + groupedlineedit.cpp + querybuilder.cpp + querybuildercompleter.cpp ) set(widgets_SRCS ${ui_SRCS}) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/baloo-widgets-4.13.2/src/groupedlineedit.cpp new/baloo-widgets-4.13.80/src/groupedlineedit.cpp --- old/baloo-widgets-4.13.2/src/groupedlineedit.cpp 1970-01-01 01:00:00.000000000 +0100 +++ new/baloo-widgets-4.13.80/src/groupedlineedit.cpp 2014-05-23 15:37:47.000000000 +0200 @@ -0,0 +1,208 @@ +/* This file is part of the Nepomuk widgets collection + Copyright (c) 2013 Denis Steckelmacher <[email protected]> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2.1 as published by the Free Software Foundation, + or any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "groupedlineedit.h" + +#include <QtGui/QStyleOptionFrameV3> +#include <QtGui/QFontMetrics> +#include <QtGui/QApplication> +#include <QtGui/QScrollBar> +#include <QtGui/QTextDocument> +#include <QtGui/QTextBlock> +#include <QtGui/QTextLayout> +#include <QtGui/QTextLine> +#include <QtGui/QPainter> +#include <QtGui/QPainterPath> +#include <QtGui/QBrush> +#include <QtGui/QColor> +#include <QtGui/QPalette> + +using namespace Baloo; + +struct GroupedLineEdit::Private +{ + struct Block { + int start; + int end; + }; + + QVector<Block> blocks; + QBrush base; +}; + +GroupedLineEdit::GroupedLineEdit(QWidget* parent) +: QPlainTextEdit(parent), + d(new Private) +{ + setWordWrapMode(QTextOption::NoWrap); + setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); + + setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + + document()->setMaximumBlockCount(1); + + // Use a transparent base, to make the rectangle visible + QPalette pal = palette(); + + d->base = pal.base(); + pal.setBrush(QPalette::Base, Qt::transparent); + + setPalette(pal); +} + +GroupedLineEdit::~GroupedLineEdit() +{ + delete d; +} + +QString GroupedLineEdit::text() const +{ + // Remove the block crosses from the text + return toPlainText(); +} + +int GroupedLineEdit::cursorPosition() const +{ + return textCursor().positionInBlock(); +} + +void GroupedLineEdit::addBlock(int start, int end) +{ + Private::Block block; + + block.start = start; + block.end = end; + + d->blocks.append(block); + viewport()->update(); +} + +void GroupedLineEdit::setCursorPosition(int position) +{ + QTextCursor c = textCursor(); + + c.setPosition(position, QTextCursor::MoveAnchor); + + setTextCursor(c); +} + +void GroupedLineEdit::setText(const QString &text) +{ + setPlainText(text); +} + +void GroupedLineEdit::clear() +{ + clear(); + removeAllBlocks(); +} + +void GroupedLineEdit::selectAll() +{ + QTextCursor c = textCursor(); + + c.select(QTextCursor::LineUnderCursor); + + setTextCursor(c); +} + +void GroupedLineEdit::removeAllBlocks() +{ + d->blocks.clear(); + viewport()->update(); +} + +QSize GroupedLineEdit::sizeHint() const +{ + QSize rs( + 40, + document()->findBlock(0).layout()->lineAt(0).height() + + document()->documentMargin() * 2 + + frameWidth() * 2 + ); + + return rs; +} + +QSize GroupedLineEdit::minimumSizeHint() const +{ + return sizeHint(); +} + +void GroupedLineEdit::keyPressEvent(QKeyEvent *e) +{ + switch (e->key()) { + case Qt::Key_Return: + case Qt::Key_Enter: + emit editingFinished(); + return; + } + + QPlainTextEdit::keyPressEvent(e); +} + +void GroupedLineEdit::paintEvent(QPaintEvent *e) +{ + static unsigned char colors[] = { + 0 , 87 , 174, + 243, 195, 0 , + 0 , 179, 119, + 235, 115, 49 , + 139, 179, 0 , + 85 , 87 , 83 , + 0 , 140, 0 , + 117, 81 , 26 + }; + + QTextLine line = document()->findBlock(0).layout()->lineAt(0); + QPainter painter(viewport()); + int color_index = 0; + + painter.setRenderHint(QPainter::Antialiasing, true); + painter.setRenderHint(QPainter::HighQualityAntialiasing, true); + + painter.fillRect(0, 0, viewport()->width(), viewport()->height(), d->base); + + Q_FOREACH(const Private::Block &block, d->blocks) { + qreal start_x = line.cursorToX(block.start, QTextLine::Trailing); + qreal end_x = line.cursorToX(block.end + 1, QTextLine::Leading); + QPainterPath path; + QRectF rectangle( + start_x - 1.0 - double(horizontalScrollBar()->value()), + 1.0, + end_x - start_x + 2.0, + double(viewport()->height() - 2) + ); + + unsigned char *c = colors + (color_index * 3); + QColor color(c[0], c[1], c[2]); + + path.addRoundedRect(rectangle, 5.0, 5.0); + painter.setPen(color); + painter.setBrush(color.lighter(180)); + painter.drawPath(path); + + color_index = (color_index + 1) & 0xf; + } + + QPlainTextEdit::paintEvent(e); +} + +#include "groupedlineedit.moc" diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/baloo-widgets-4.13.2/src/groupedlineedit.h new/baloo-widgets-4.13.80/src/groupedlineedit.h --- old/baloo-widgets-4.13.2/src/groupedlineedit.h 1970-01-01 01:00:00.000000000 +0100 +++ new/baloo-widgets-4.13.80/src/groupedlineedit.h 2014-05-23 15:37:47.000000000 +0200 @@ -0,0 +1,130 @@ +/* This file is part of the Baloo widgets collection + Copyright (c) 2013 Denis Steckelmacher <[email protected]> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2.1 as published by the Free Software Foundation, + or any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef __GROUPEDLINEEDIT_H__ +#define __GROUPEDLINEEDIT_H__ + +#include <QtGui/QPlainTextEdit> + +#include "widgets_export.h" + +namespace Baloo { + +/** + * \class GroupedLineEdit groupedlineedit.h baloo/groupedlineedit.h + * \brief Single-line text editor with grouped terms support + * + * This widget looks like a QLineEdit, but terms can be grouped in it. A group + * consists of terms drawn inside a rounded rectangle. Rectangles have different + * colors, that allow the user to recognize parts of the input. They can be + * nested. + * + * This widget can be used to show how a line can be tokenized or parsed. For + * instance, the QueryBuilder widget uses this widget to show the filters of a + * query, but a mail client can also use the control to highlight e-mail + * addresses. + */ +class BALOO_WIDGETS_EXPORT GroupedLineEdit : public QPlainTextEdit +{ + Q_OBJECT + + public: + explicit GroupedLineEdit(QWidget *parent = 0); + virtual ~GroupedLineEdit(); + + /** + * Text displayed in this control. Use this method instead of + * toPlainText() as it is garanteed that this method will return exactly + * what the user sees. + */ + QString text() const; + + /** + * Current cursor position. The cursor position starts at 0 when the + * cursor is completely at the left of the control (for right-to-left + * languages) and goes to text().length() when the cursor is completely + * at the right of the control. + */ + int cursorPosition() const; + + /** + * Set the cursor position + * + * \sa cursorPosition + */ + void setCursorPosition(int position); + + /** + * Set the text dislayed by the control. Calling this method removes all + * the blocks. + * + * \sa text + * \sa removeAllBlocks + */ + void setText(const QString &text); + + /** + * Clear the text and the blocks contained in the widget. + */ + void clear(); + + /** + * Select all the text present in the control. + */ + void selectAll(); + + /** + * Remove all the blocks that were present in the control. The text is + * not changed, but no block will be drawn any more. + */ + void removeAllBlocks(); + + /** + * Add a block to the control. A block represents a group and is + * identified by the indexes of the first and the last characters in it. + * These limits are inclusive. + * + * The control maintains a list of block colors, that are cycled through + * at each block insertion. If you want the blocks to always have the + * same color even if they are removed and then re-added, always add + * them in the same order. + */ + void addBlock(int start, int end); + + virtual QSize sizeHint() const; + virtual QSize minimumSizeHint() const; + + signals: + /** + * Signal triggered when the user presses Enter or Return in the control + */ + void editingFinished(); + + protected: + virtual void paintEvent(QPaintEvent *e); + virtual void keyPressEvent(QKeyEvent *e); + + private: + struct Private; + Private *d; +}; + +} + +#endif \ No newline at end of file diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/baloo-widgets-4.13.2/src/kedittagsdialog_p.h new/baloo-widgets-4.13.80/src/kedittagsdialog_p.h --- old/baloo-widgets-4.13.2/src/kedittagsdialog_p.h 2014-03-15 16:18:39.000000000 +0100 +++ new/baloo-widgets-4.13.80/src/kedittagsdialog_p.h 2014-05-23 15:37:47.000000000 +0200 @@ -1,20 +1,19 @@ -/***************************************************************************** - * Copyright (C) 2009 by Peter Penz <[email protected]> * - * * - * This library is free software; you can redistribute it and/or * - * modify it under the terms of the GNU Library General Public * - * License version 2 as published by the Free Software Foundation. * - * * - * This library is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * - * Library General Public License for more details. * - * * - * You should have received a copy of the GNU Library General Public License * - * along with this library; see the file COPYING.LIB. If not, write to * - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * - * Boston, MA 02110-1301, USA. * - *****************************************************************************/ +/* + * Copyright (C) 2009 by Peter Penz <[email protected]> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see <http://www.gnu.org/licenses/>. + */ #ifndef KEDIT_TAGS_DIALOG_H #define KEDIT_TAGS_DIALOG_H diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/baloo-widgets-4.13.2/src/querybuilder.cpp new/baloo-widgets-4.13.80/src/querybuilder.cpp --- old/baloo-widgets-4.13.2/src/querybuilder.cpp 1970-01-01 01:00:00.000000000 +0100 +++ new/baloo-widgets-4.13.80/src/querybuilder.cpp 2014-05-23 15:37:47.000000000 +0200 @@ -0,0 +1,180 @@ +/* This file is part of the Nepomuk widgets collection + Copyright (c) 2013 Denis Steckelmacher <[email protected]> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2.1 as published by the Free Software Foundation, + or any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "querybuilder.h" +#include "groupedlineedit.h" +#include "querybuildercompleter_p.h" + +#include <baloo/completionproposal.h> +#include <baloo/queryparser.h> +#include <baloo/term.h> + +using namespace Baloo; + +struct QueryBuilder::Private +{ + QueryParser *parser; + QueryBuilderCompleter *completer; + + bool parsing_enabled; +}; + +static int termStart(const Baloo::Term &term) +{ + return term.userData(QLatin1String("start_position")).toInt(); +} + +static int termEnd(const Baloo::Term &term) +{ + return term.userData(QLatin1String("end_position")).toInt(); +} + +QueryBuilder::QueryBuilder(QueryParser *parser, QWidget *parent) +: GroupedLineEdit(parent), + d(new Private) +{ + d->parser = parser; + d->completer = new QueryBuilderCompleter(this); + d->parsing_enabled = true; + + connect(this, SIGNAL(textChanged()), + this, SLOT(reparse())); + connect(d->completer, SIGNAL(proposalSelected(CompletionProposal*,QString)), + this, SLOT(proposalSelected(CompletionProposal*,QString))); +} + +void QueryBuilder::setParsingEnabled(bool enable) +{ + d->parsing_enabled = enable; +} + +bool QueryBuilder::parsingEnabled() const +{ + return d->parsing_enabled; +} + +void QueryBuilder::handleTerm(const Term &term) +{ + // If the term has subterms (AND or OR), highlight these + if (term.subTerms().count() > 0) { + Q_FOREACH (const Term &subterm, term.subTerms()) { + addBlock(termStart(subterm), termEnd(subterm)); + handleTerm(subterm); + } + } +} + +void QueryBuilder::reparse() +{ + if (!parsingEnabled()) { + d->completer->hide(); + return; + } + + int position = cursorPosition(); + QString t = text(); + + Query query = d->parser->parse(t, QueryParser::DetectFilenamePattern, position); + Term term(query.term()); + + // Extract the term just before the cursor + QString term_before_cursor; + + for (int i=position-1; i>=0 && !t.at(i).isSpace(); --i) { + term_before_cursor.prepend(t.at(i)); + } + + // Highlight the input field + removeAllBlocks(); + handleTerm(term); + + setCursorPosition(position); + + // Build the list of auto-completions + QList<CompletionProposal *> proposals = d->parser->completionProposals(); + + if (proposals.count() > 0) { + d->completer->clear(); + + Q_FOREACH(CompletionProposal *proposal, d->parser->completionProposals()) { + d->completer->addProposal(proposal, term_before_cursor); + } + + d->completer->open(); + } else { + // No completion available + d->completer->hide(); + } +} + +void QueryBuilder::proposalSelected(CompletionProposal *proposal, + const QString &value) +{ + QString t = text(); + + // Term before the cursor (if any) + int term_before_cursor_pos = cursorPosition(); + QString term_before_cursor; + + while (term_before_cursor_pos > 0 && !t.at(term_before_cursor_pos - 1).isSpace()) { + term_before_cursor.prepend(t.at(term_before_cursor_pos - 1)); + --term_before_cursor_pos; + } + + // Build the text that will be used to auto-complete the query + QStringList pattern = proposal->pattern(); + QString replacement; + int first_unmatched_part = proposal->lastMatchedPart() + 1; + int cursor_offset = -1; + + if (!term_before_cursor.isEmpty()) { + // The last matched part will be replaced by value, so count it + // as unmatched to have it replaced + --first_unmatched_part; + } + + for (int i=first_unmatched_part; i<pattern.count(); ++i) { + const QString &part = pattern.at(i); + + if (!replacement.isEmpty()) { + replacement += QLatin1Char(' '); + } + + if (part.at(0) == QLatin1Char('%')) { + cursor_offset = replacement.length() + value.length(); + replacement += value; + } else { + // FIXME: This arbitrarily selects a term even if it does not fit + // gramatically. + replacement += part.section(QLatin1Char('|'), 0, 0); + } + } + + // setText() will cause a reparse(), that will invalidate proposal + int put_cursor_at = term_before_cursor_pos + + (cursor_offset >= 0 ? cursor_offset : replacement.length()); + + // Auto-complete, setText() triggers a reparse + t.replace(term_before_cursor_pos, term_before_cursor.length(), replacement); + + setText(t); + setCursorPosition(put_cursor_at); +} + +#include "querybuilder.moc" diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/baloo-widgets-4.13.2/src/querybuilder.h new/baloo-widgets-4.13.80/src/querybuilder.h --- old/baloo-widgets-4.13.2/src/querybuilder.h 1970-01-01 01:00:00.000000000 +0100 +++ new/baloo-widgets-4.13.80/src/querybuilder.h 2014-05-23 15:37:47.000000000 +0200 @@ -0,0 +1,70 @@ +/* This file is part of the Nepomuk widgets collection + Copyright (c) 2013 Denis Steckelmacher <[email protected]> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2.1 as published by the Free Software Foundation, + or any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef __QUERYEDITOR_H__ +#define __QUERYEDITOR_H__ + +#include "widgets_export.h" +#include "groupedlineedit.h" + +namespace Baloo { + +class CompletionProposal; +class QueryParser; +class Term; + +class BALOO_WIDGETS_EXPORT QueryBuilder : public GroupedLineEdit +{ + Q_OBJECT + + public: + explicit QueryBuilder(QueryParser *parser, QWidget *parent = 0); + + /** + * @brief Parse the user query and provide syntax-highlighting and auto-completion + * + * If parsing is disabled, the query builder acts like a simple + * QLineEdit without any fancy coloring. If parsing is enabled, all the + * features are exposed to the user. + * + * By default, parsing is enabled. + */ + void setParsingEnabled(bool enable); + + /** + * @return whether parsing is enabled + */ + bool parsingEnabled() const; + + private: + void handleTerm(const Term &term); + + private slots: + void reparse(); + void proposalSelected(CompletionProposal *proposal, + const QString &value); + + private: + struct Private; + Private *d; +}; + +} + +#endif \ No newline at end of file diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/baloo-widgets-4.13.2/src/querybuildercompleter.cpp new/baloo-widgets-4.13.80/src/querybuildercompleter.cpp --- old/baloo-widgets-4.13.2/src/querybuildercompleter.cpp 1970-01-01 01:00:00.000000000 +0100 +++ new/baloo-widgets-4.13.80/src/querybuildercompleter.cpp 2014-05-23 15:37:47.000000000 +0200 @@ -0,0 +1,254 @@ +/* This file is part of the Baloo widgets collection + Copyright (c) 2013 Denis Steckelmacher <[email protected]> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2.1 as published by the Free Software Foundation, + or any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "querybuildercompleter_p.h" + +#include <baloo/completionproposal.h> +#include <klocalizedstring.h> + +#include <QtGui/QListWidget> +#include <QtGui/QListWidgetItem> +#include <QtGui/QCalendarWidget> +#include <QtGui/QHBoxLayout> +#include <QtGui/QVBoxLayout> +#include <QtGui/QLabel> +#include <QtGui/QKeyEvent> +#include <QtGui/QTextDocument> // for Qt::escape + +using namespace Baloo; + +QueryBuilderCompleter::QueryBuilderCompleter(QWidget *parent) +: QListWidget(parent) +{ + // Display the completer in its own non-decorated popup + setWindowFlags(Qt::Tool | Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint); + setAttribute(Qt::WA_X11NetWmWindowTypeCombo); + setAttribute(Qt::WA_ShowWithoutActivating); + + setFocusPolicy(Qt::NoFocus); + setFocusProxy(parent); + setFrameShape(NoFrame); + setUniformItemSizes(true); + + parent->installEventFilter(this); + + connect(this, SIGNAL(itemActivated(QListWidgetItem*)), + this, SLOT(proposalActivated(QListWidgetItem*))); +} + +QWidget *QueryBuilderCompleter::widgetForProposal(CompletionProposal *proposal, + const QString &value) +{ + // Create a label representing the pattern of the proposal + QString proposal_text = QLatin1String(" "); + QStringList pattern = proposal->pattern(); + + for (int i=0; i<pattern.count(); ++i) { + const QString &part = pattern.at(i); + + if (i != 0) { + proposal_text += QLatin1Char(' '); + } + + if (part.at(0) == QLatin1Char('%')) { + proposal_text += QLatin1String("<em>"); + + if (!value.isEmpty()) { + proposal_text += value; + } else { + switch (proposal->type()) { + case CompletionProposal::NoType: + proposal_text += i18nc("Pattern placeholder having no specific type", "[something]"); + break; + + case CompletionProposal::DateTime: + proposal_text += i18nc("Pattern placeholder of date-time type", "[date and time]"); + break; + + case CompletionProposal::Tag: + proposal_text += i18nc("Pattern placeholder for a tag name", "[tag name]"); + break; + + case CompletionProposal::Contact: + proposal_text += i18nc("Pattern placeholder for a contact identifier", "[contact]"); + break; + + case CompletionProposal::Email: + proposal_text += i18nc("Pattern placeholder for an e-mail address", "[email address]"); + } + } + + proposal_text += QLatin1String("</em>"); + } else if (i <= proposal->lastMatchedPart()) { + proposal_text += QLatin1String("<strong>") + Qt::escape(part) + QLatin1String("</strong>"); + } else { + proposal_text += Qt::escape(part); + } + } + + // Widget displaying the proposal + QWidget *widget = new QWidget(this); + QLabel *title_label = new QLabel(proposal->description().toString(), widget); + QLabel *content_label = new QLabel(proposal_text); + QVBoxLayout *vlayout = new QVBoxLayout(widget); + + QFont title_font(title_label->font()); + title_font.setBold(true); + title_label->setFont(title_font); + + title_label->setTextFormat(Qt::PlainText); + content_label->setTextFormat(Qt::RichText); + + vlayout->addWidget(title_label); + vlayout->addWidget(content_label); + + return widget; +} + +QString QueryBuilderCompleter::valueStartingWith(const QStringList &strings, + const QString &prefix) const +{ + QStringList::const_iterator it = qLowerBound(strings, prefix); + + if (it == strings.end() || !(*it).startsWith(prefix)) { + return QString(); + } else { + return QLatin1Char('"') + *it + QLatin1Char('"'); + } +} + +void QueryBuilderCompleter::addProposal(CompletionProposal *proposal, + const QString &prefix) +{ + QString value; + QStringList pattern = proposal->pattern(); + + // If the term the user is entering is a placeholder, pre-fill it + if (!prefix.isEmpty() && + proposal->lastMatchedPart() < pattern.size() && + pattern.at(proposal->lastMatchedPart()).at(0) == QLatin1Char('%')) + { + switch (proposal->type()) { +#if 0 + case CompletionProposal::Contact: + value = valueStartingWith(parser->allContacts(), prefix); + break; + case CompletionProposal::Tag: + value = valueStartingWith(parser->allTags(), prefix); + break; + case CompletionProposal::Email: + value = valueStartingWith(parser->allEmailAddresses(), prefix); + break; +#endif + case CompletionProposal::DateTime: + value = QDate::currentDate().toString(Qt::DefaultLocaleShortDate); + break; + default: + break; + } + } + + // Add a new item to the list + QListWidgetItem *item = new QListWidgetItem(this); + QWidget *widget = widgetForProposal(proposal, value); + + item->setData(Qt::UserRole, QVariant::fromValue(static_cast<void *>(proposal))); + item->setData(Qt::UserRole + 1, value); + item->setSizeHint(widget->sizeHint()); + + addItem(item); + setItemWidget(item, widget); + + if (count() == 1 || !value.isEmpty()) { + // Select the first item, or an interesting completion if possible + setCurrentRow(count() - 1); + } +} + +void QueryBuilderCompleter::open() +{ + if (count() == 0) { + return; + } + + QWidget *p = parentWidget(); + QPoint parent_position = p->mapToGlobal(QPoint(0, 0)); + + // Display the popup just below the parent widget + resize(p->width(), count() * item(0)->sizeHint().height()); + move(parent_position.x(), parent_position.y() + p->height()); + + show(); +} + +void QueryBuilderCompleter::proposalActivated(QListWidgetItem *item) +{ + CompletionProposal *proposal = + static_cast<CompletionProposal *>( + item->data(Qt::UserRole).value<void *>() + ); + + emit proposalSelected(proposal, item->data(Qt::UserRole + 1).toString()); +} + +bool QueryBuilderCompleter::eventFilter(QObject *, QEvent *event) +{ + bool rs = false; + + if (!isVisible()) { + return rs; // Don't block events when the completer is not open + } + + if (event->type() == QEvent::KeyPress) { + QKeyEvent *keypress = static_cast<QKeyEvent *>(event); + + switch (keypress->key()) { + case Qt::Key_Up: + if (currentRow() > 0) { + setCurrentRow(currentRow() - 1); + } + break; + + case Qt::Key_Down: + if (currentRow() < count() - 1) { + setCurrentRow(currentRow() + 1); + } + break; + + case Qt::Key_Enter: + case Qt::Key_Tab: + case Qt::Key_Return: + proposalActivated(currentItem()); + rs = true; // In Dolphin, don't trigger a search when Enter is pressed in the auto-completion box + break; + + case Qt::Key_Escape: + hide(); + rs = true; + break; + + default: + break; + } + } + + return rs; +} + +#include "querybuildercompleter_p.moc" diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/baloo-widgets-4.13.2/src/querybuildercompleter_p.h new/baloo-widgets-4.13.80/src/querybuildercompleter_p.h --- old/baloo-widgets-4.13.2/src/querybuildercompleter_p.h 1970-01-01 01:00:00.000000000 +0100 +++ new/baloo-widgets-4.13.80/src/querybuildercompleter_p.h 2014-05-23 15:37:47.000000000 +0200 @@ -0,0 +1,62 @@ +/* This file is part of the Nepomuk widgets collection + Copyright (c) 2013 Denis Steckelmacher <[email protected]> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2.1 as published by the Free Software Foundation, + or any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef __QUERYBUILDERCOMPLETER_H__ +#define __QUERYBUILDERCOMPLETER_H__ + +#include <QtGui/QListWidget> + +class QListWidgetItem; + +namespace Baloo { + +class CompletionProposal; + +class QueryBuilderCompleter : public QListWidget +{ + Q_OBJECT + + public: + explicit QueryBuilderCompleter(QWidget *parent); + + void addProposal(CompletionProposal *proposal, const QString &prefix); + + public slots: + void open(); + + private slots: + void proposalActivated(QListWidgetItem *item); + + protected: + virtual bool eventFilter(QObject *, QEvent *event); + + signals: + void proposalSelected(CompletionProposal *proposal, + const QString &value); + + private: + QString valueStartingWith(const QStringList &strings, + const QString &prefix) const; + QWidget *widgetForProposal(CompletionProposal *proposal, + const QString &value); +}; + +} + +#endif diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/baloo-widgets-4.13.2/test/CMakeLists.txt new/baloo-widgets-4.13.80/test/CMakeLists.txt --- old/baloo-widgets-4.13.2/test/CMakeLists.txt 2014-03-15 16:18:39.000000000 +0100 +++ new/baloo-widgets-4.13.80/test/CMakeLists.txt 2014-05-23 15:37:47.000000000 +0200 @@ -31,3 +31,9 @@ baloowidgets ) +kde4_add_executable(querybuilderapp TEST querybuilderapp.cpp ) +target_link_libraries(querybuilderapp + ${KDE4_KIO_LIBS} + ${BALOO_LIBRARIES} + baloowidgets +) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/baloo-widgets-4.13.2/test/querybuilderapp.cpp new/baloo-widgets-4.13.80/test/querybuilderapp.cpp --- old/baloo-widgets-4.13.2/test/querybuilderapp.cpp 1970-01-01 01:00:00.000000000 +0100 +++ new/baloo-widgets-4.13.80/test/querybuilderapp.cpp 2014-05-23 15:37:47.000000000 +0200 @@ -0,0 +1,38 @@ +/* This file is part of the Nepomuk widgets collection + Copyright (c) 2013 Denis Steckelmacher <[email protected]> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2.1 as published by the Free Software Foundation, + or any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "querybuilder.h" + +#include <QApplication> + +#include <baloo/queryparser.h> +#include <kcomponentdata.h> + +int main(int argc, char **argv) +{ + QApplication app(argc, argv); + KComponentData data("QueryBuilderApp"); + + Baloo::QueryParser parser; + Baloo::QueryBuilder builder(&parser, 0); + + builder.show(); + + return app.exec(); +} -- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
