Skip to content

Commit 85b26a9

Browse files
author
audioprog
committed
AutoComplete with Tab-Key
Disable Wheel-Event in SpinBox
1 parent c55f5b4 commit 85b26a9

6 files changed

+103
-5
lines changed

Diff for: AudioDatenbank.pro

+4-4
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ SOURCES += main.cpp\
4646
lsKeyAndFilterListEditor.cpp \
4747
lsGlobalSettings.cpp \
4848
lsMp3Converter.cpp \
49-
LsFileList.cpp \
5049
CompletedLineEdit.cpp \
5150
ListSelectDialog.cpp \
5251
ListPrintDialog.cpp \
@@ -150,8 +149,9 @@ SOURCES += main.cpp\
150149
taglib/xm/xmfile.cpp \
151150
taglib/xm/xmproperties.cpp \
152151
lsOutputSource.cpp \
153-
lsVariantList2D.cpp \
154-
lsTextEdit.cpp
152+
lsVariantList2D.cpp \
153+
LsFileList.cpp \
154+
lsSpinBox.cpp
155155

156156
HEADERS += mainwindow.h \
157157
Einzelbeitrag.h \
@@ -272,7 +272,7 @@ HEADERS += mainwindow.h \
272272
taglib/taglib_config.h \
273273
lsOutputSource.h \
274274
lsVariantList2D.h \
275-
lsTextEdit.h
275+
lsSpinBox.h
276276

277277
FORMS += mainwindow.ui \
278278
Einzelbeitrag.ui \

Diff for: CompletedLineEdit.cpp

+23
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,29 @@ void CompletedLineEdit::readWordsAndCreateCompleter(bool isReread)
9898
this->c->setWrapAround(false);
9999
}
100100

101+
bool CompletedLineEdit::event(QEvent* event)
102+
{
103+
if (event->type() != QEvent::KeyPress)
104+
{
105+
return QLineEdit::event(event);
106+
}
107+
108+
if (reinterpret_cast<QKeyEvent*>(event)->key() != Qt::Key_Tab)
109+
{
110+
return QLineEdit::event(event);
111+
}
112+
113+
if (c->popup()->currentIndex().isValid())
114+
{
115+
insertCompletion(c->popup()->model()->data(c->popup()->currentIndex()).toString());
116+
c->popup()->hide();
117+
event->accept();
118+
return true;
119+
}
120+
121+
return false;
122+
}
123+
101124
void CompletedLineEdit::createFromSimpleDatabaseTable(QSqlDatabase db, const QString& tableName)
102125
{
103126
this->db = db;

Diff for: CompletedLineEdit.h

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ class CompletedLineEdit : public QLineEdit
2222
void readWordsAndCreateCompleter( bool isReread = false );
2323

2424
protected:
25+
bool event(QEvent* event) Q_DECL_OVERRIDE;
2526
void keyPressEvent(QKeyEvent *e) Q_DECL_OVERRIDE;
2627
void focusInEvent(QFocusEvent *e) Q_DECL_OVERRIDE;
2728

Diff for: Einzelbeitrag.ui

+6-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@
7979
<item row="0" column="1">
8080
<layout class="QHBoxLayout" name="horizontalLayout_3">
8181
<item>
82-
<widget class="QSpinBox" name="titelnummerSpinBox">
82+
<widget class="lsSpinBox" name="titelnummerSpinBox">
8383
<property name="sizePolicy">
8484
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
8585
<horstretch>0</horstretch>
@@ -306,6 +306,11 @@
306306
<extends>QLineEdit</extends>
307307
<header>CompletedLineEdit.h</header>
308308
</customwidget>
309+
<customwidget>
310+
<class>lsSpinBox</class>
311+
<extends>QSpinBox</extends>
312+
<header>lsSpinBox.h</header>
313+
</customwidget>
309314
</customwidgets>
310315
<tabstops>
311316
<tabstop>nameLineEdit</tabstop>

Diff for: lsSpinBox.cpp

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* (C) 2016 [email protected]
3+
*
4+
***************************************************************************
5+
* This is free software; you can redistribute it and/or modify *
6+
* it under the terms of the GNU Lesser General Public License version *
7+
* 2.1 as published by the Free Software Foundation. *
8+
* *
9+
* This software is distributed in the hope that it will be useful, but *
10+
* WITHOUT ANY WARRANTY; without even the implied warranty of *
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
12+
* Lesser General Public License for more details. *
13+
* *
14+
* You should have received a copy of the GNU Lesser General Public *
15+
* License along with this library; if not, write to the Free Software *
16+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA *
17+
* 02110-1301 USA *
18+
* *
19+
* Alternatively, this file is available under the Mozilla Public *
20+
* License Version 1.1. You may obtain a copy of the License at *
21+
* http://www.mozilla.org/MPL/ *
22+
***************************************************************************/
23+
24+
#include "lsSpinBox.h"
25+
26+
#include <QWheelEvent>
27+
28+
void lsSpinBox::wheelEvent(QWheelEvent* event)
29+
{
30+
event->accept();
31+
}

Diff for: lsSpinBox.h

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* (C) 2016 [email protected]
3+
*
4+
***************************************************************************
5+
* This is free software; you can redistribute it and/or modify *
6+
* it under the terms of the GNU Lesser General Public License version *
7+
* 2.1 as published by the Free Software Foundation. *
8+
* *
9+
* This software is distributed in the hope that it will be useful, but *
10+
* WITHOUT ANY WARRANTY; without even the implied warranty of *
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
12+
* Lesser General Public License for more details. *
13+
* *
14+
* You should have received a copy of the GNU Lesser General Public *
15+
* License along with this library; if not, write to the Free Software *
16+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA *
17+
* 02110-1301 USA *
18+
* *
19+
* Alternatively, this file is available under the Mozilla Public *
20+
* License Version 1.1. You may obtain a copy of the License at *
21+
* http://www.mozilla.org/MPL/ *
22+
***************************************************************************/
23+
24+
#ifndef LSSPINBOX_H
25+
#define LSSPINBOX_H
26+
27+
#include <QSpinBox>
28+
29+
class lsSpinBox : public QSpinBox
30+
{
31+
public:
32+
lsSpinBox( QWidget* parent = 0 ) : QSpinBox(parent) {}
33+
34+
protected:
35+
void wheelEvent( QWheelEvent* event );
36+
};
37+
38+
#endif // LSSPINBOX_H

0 commit comments

Comments
 (0)