mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Merge branch 'tagwidget-pr' of github.com:mguentner/subsurface
This commit is contained in:
commit
7966f72fb7
5 changed files with 146 additions and 83 deletions
|
@ -1,4 +1,12 @@
|
||||||
/*
|
/*
|
||||||
|
* Copyright (c) 2013 Maximilian Güntner <maximilian.guentner@gmail.com>
|
||||||
|
*
|
||||||
|
* This file is subject to the terms and conditions of version 2 of
|
||||||
|
* the GNU General Public License. See the file gpl-2.0.txt in the main
|
||||||
|
* directory of this archive for more details.
|
||||||
|
*
|
||||||
|
* Original License:
|
||||||
|
*
|
||||||
* This file is part of the Nepomuk widgets collection
|
* This file is part of the Nepomuk widgets collection
|
||||||
* Copyright (c) 2013 Denis Steckelmacher <steckdenis@yahoo.fr>
|
* Copyright (c) 2013 Denis Steckelmacher <steckdenis@yahoo.fr>
|
||||||
*
|
*
|
||||||
|
@ -34,8 +42,7 @@
|
||||||
#include <QtGui/QColor>
|
#include <QtGui/QColor>
|
||||||
#include <QtGui/QPalette>
|
#include <QtGui/QPalette>
|
||||||
|
|
||||||
struct GroupedLineEdit::Private
|
struct GroupedLineEdit::Private {
|
||||||
{
|
|
||||||
struct Block {
|
struct Block {
|
||||||
int start;
|
int start;
|
||||||
int end;
|
int end;
|
||||||
|
@ -108,9 +115,7 @@ QStringList GroupedLineEdit::getBlockStringList()
|
||||||
void GroupedLineEdit::setCursorPosition(int position)
|
void GroupedLineEdit::setCursorPosition(int position)
|
||||||
{
|
{
|
||||||
QTextCursor c = textCursor();
|
QTextCursor c = textCursor();
|
||||||
|
|
||||||
c.setPosition(position, QTextCursor::MoveAnchor);
|
c.setPosition(position, QTextCursor::MoveAnchor);
|
||||||
|
|
||||||
setTextCursor(c);
|
setTextCursor(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -165,7 +170,6 @@ void GroupedLineEdit::keyPressEvent(QKeyEvent *e)
|
||||||
emit editingFinished();
|
emit editingFinished();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
QPlainTextEdit::keyPressEvent(e);
|
QPlainTextEdit::keyPressEvent(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,11 @@
|
||||||
/* Original License:
|
/*
|
||||||
|
* Copyright (c) 2013 Maximilian Güntner <maximilian.guentner@gmail.com>
|
||||||
|
*
|
||||||
|
* This file is subject to the terms and conditions of version 2 of
|
||||||
|
* the GNU General Public License. See the file gpl-2.0.txt in the main
|
||||||
|
* directory of this archive for more details.
|
||||||
|
*
|
||||||
|
* Original License:
|
||||||
*
|
*
|
||||||
* This file is part of the Nepomuk widgets collection
|
* This file is part of the Nepomuk widgets collection
|
||||||
* Copyright (c) 2013 Denis Steckelmacher <steckdenis@yahoo.fr>
|
* Copyright (c) 2013 Denis Steckelmacher <steckdenis@yahoo.fr>
|
||||||
|
|
|
@ -840,6 +840,24 @@
|
||||||
<header>qt-ui/tagwidget.h</header>
|
<header>qt-ui/tagwidget.h</header>
|
||||||
</customwidget>
|
</customwidget>
|
||||||
</customwidgets>
|
</customwidgets>
|
||||||
|
<tabstops>
|
||||||
|
<tabstop>scrollArea</tabstop>
|
||||||
|
<tabstop>dateTimeEdit</tabstop>
|
||||||
|
<tabstop>airtemp</tabstop>
|
||||||
|
<tabstop>watertemp</tabstop>
|
||||||
|
<tabstop>location</tabstop>
|
||||||
|
<tabstop>coordinates</tabstop>
|
||||||
|
<tabstop>divemaster</tabstop>
|
||||||
|
<tabstop>buddy</tabstop>
|
||||||
|
<tabstop>suit</tabstop>
|
||||||
|
<tabstop>tagWidget</tabstop>
|
||||||
|
<tabstop>notes</tabstop>
|
||||||
|
<tabstop>notesButtonBox</tabstop>
|
||||||
|
<tabstop>scrollArea_2</tabstop>
|
||||||
|
<tabstop>equipmentButtonBox</tabstop>
|
||||||
|
<tabstop>scrollArea_3</tabstop>
|
||||||
|
<tabstop>scrollArea_4</tabstop>
|
||||||
|
</tabstops>
|
||||||
<resources/>
|
<resources/>
|
||||||
<connections/>
|
<connections/>
|
||||||
</ui>
|
</ui>
|
||||||
|
|
|
@ -1,10 +1,12 @@
|
||||||
#include "tagwidget.h"
|
#include "tagwidget.h"
|
||||||
#include <QPair>
|
#include <QPair>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
#include <QAbstractItemView>
|
||||||
|
|
||||||
TagWidget::TagWidget(QWidget *parent) : GroupedLineEdit(parent), m_completer(NULL)
|
TagWidget::TagWidget(QWidget *parent) : GroupedLineEdit(parent), m_completer(NULL)
|
||||||
{
|
{
|
||||||
connect(this, SIGNAL(cursorPositionChanged()), this, SLOT(reparse()));
|
connect(this, SIGNAL(cursorPositionChanged()), this, SLOT(reparse()));
|
||||||
|
connect(this, SIGNAL(textChanged()), this, SLOT(reparse()));
|
||||||
|
|
||||||
addColor(QColor(0x00, 0xAE, 0xFF));
|
addColor(QColor(0x00, 0xAE, 0xFF));
|
||||||
addColor(QColor(0x00, 0x78, 0xB0));
|
addColor(QColor(0x00, 0x78, 0xB0));
|
||||||
|
@ -15,6 +17,7 @@ void TagWidget::setCompleter(QCompleter *completer)
|
||||||
m_completer = completer;
|
m_completer = completer;
|
||||||
m_completer->setWidget(this);
|
m_completer->setWidget(this);
|
||||||
connect(m_completer, SIGNAL(activated(QString)), this, SLOT(completionSelected(QString)));
|
connect(m_completer, SIGNAL(activated(QString)), this, SLOT(completionSelected(QString)));
|
||||||
|
connect(m_completer, SIGNAL(highlighted(QString)), this, SLOT(completionSelected(QString)));
|
||||||
}
|
}
|
||||||
|
|
||||||
QPair<int,int> TagWidget::getCursorTagPosition() {
|
QPair<int,int> TagWidget::getCursorTagPosition() {
|
||||||
|
@ -98,7 +101,18 @@ void TagWidget::reparse()
|
||||||
currentText = "";
|
currentText = "";
|
||||||
if (m_completer) {
|
if (m_completer) {
|
||||||
m_completer->setCompletionPrefix(currentText);
|
m_completer->setCompletionPrefix(currentText);
|
||||||
|
if (m_completer->completionCount() == 1) {
|
||||||
|
if (m_completer->currentCompletion() == currentText) {
|
||||||
|
QAbstractItemView *popup = m_completer->popup();
|
||||||
|
if (popup)
|
||||||
|
popup->hide();
|
||||||
|
}
|
||||||
|
else
|
||||||
m_completer->complete();
|
m_completer->complete();
|
||||||
|
|
||||||
|
} else {
|
||||||
|
m_completer->complete();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -133,3 +147,21 @@ void TagWidget::clear() {
|
||||||
GroupedLineEdit::clear();
|
GroupedLineEdit::clear();
|
||||||
blockSignals(false);
|
blockSignals(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TagWidget::keyPressEvent(QKeyEvent *e) {
|
||||||
|
switch (e->key()) {
|
||||||
|
case Qt::Key_Return:
|
||||||
|
case Qt::Key_Enter:
|
||||||
|
/*
|
||||||
|
* Fake the QLineEdit behaviour by simply
|
||||||
|
* closing the QAbstractViewitem
|
||||||
|
*/
|
||||||
|
if (m_completer) {
|
||||||
|
QAbstractItemView *popup = m_completer->popup();
|
||||||
|
if (popup)
|
||||||
|
popup->hide();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
GroupedLineEdit::keyPressEvent(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,8 @@ public:
|
||||||
public slots:
|
public slots:
|
||||||
void reparse();
|
void reparse();
|
||||||
void completionSelected(QString);
|
void completionSelected(QString);
|
||||||
|
protected:
|
||||||
|
void keyPressEvent(QKeyEvent *e);
|
||||||
private:
|
private:
|
||||||
QCompleter *m_completer;
|
QCompleter *m_completer;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Reference in a new issue