Improve UI of db query widget

* Move query options into menu so it is possible to add more
  without being limited by available space
* Trigger the last query action when hitting the enter key
* Change order of elements; I guess it looks better with buttons
  and fields to be used at the top
This commit is contained in:
Martchus 2019-09-02 20:37:31 +02:00
parent d3f84c4c39
commit a94f2e3675
3 changed files with 125 additions and 155 deletions

View File

@ -75,22 +75,30 @@ DbQueryWidget::DbQueryWidget(TagEditorWidget *tagEditorWidget, QWidget *parent)
m_ui->overrideCheckBox->setChecked(values().dbQuery.override);
// setup menu
m_insertPresentDataAction = m_menu->addAction(tr("Insert present data"));
const auto searchIcon = QIcon::fromTheme(QStringLiteral("search"));
m_searchMusicBrainzAction = m_lastSearchAction = m_menu->addAction(tr("Query MusicBrainz"));
m_searchMusicBrainzAction->setIcon(searchIcon);
m_searchMusicBrainzAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_M));
connect(m_searchMusicBrainzAction, &QAction::triggered, this, &DbQueryWidget::searchMusicBrainz);
m_searchLyricsWikiaAction = m_menu->addAction(tr("Query LyricsWikia"));
m_searchLyricsWikiaAction->setIcon(searchIcon);
m_searchLyricsWikiaAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_L));
connect(m_searchLyricsWikiaAction, &QAction::triggered, this, &DbQueryWidget::searchLyricsWikia);
m_menu->addSeparator();
m_insertPresentDataAction = m_menu->addAction(tr("Use present data as search criteria"));
m_insertPresentDataAction->setIcon(QIcon::fromTheme(QStringLiteral("edit-copy")));
m_insertPresentDataAction->setEnabled(m_tagEditorWidget->activeTagEdit());
connect(m_insertPresentDataAction, &QAction::triggered, this, &DbQueryWidget::insertSearchTermsFromActiveTagEdit);
QAction *clearSearchCriteria = m_menu->addAction(tr("Clear search criteria"));
auto *const clearSearchCriteria = m_menu->addAction(tr("Clear search criteria"));
clearSearchCriteria->setIcon(QIcon::fromTheme(QStringLiteral("edit-clear")));
connect(clearSearchCriteria, &QAction::triggered, this, &DbQueryWidget::clearSearchCriteria);
m_ui->menuPushButton->setMenu(m_menu);
m_ui->searchPushButton->setMenu(m_menu);
// ensure fieldsGroupBox takes only minimal space (initially)
m_ui->splitter->setSizes({ 1000, 1 });
m_ui->splitter->setSizes({ 1, 1000 });
// connect signals and slots
connect(m_ui->abortPushButton, &QPushButton::clicked, this, &DbQueryWidget::abortSearch);
connect(m_ui->searchMusicBrainzPushButton, &QPushButton::clicked, this, &DbQueryWidget::searchMusicBrainz);
connect(m_ui->searchLyricsWikiaPushButton, &QPushButton::clicked, this, &DbQueryWidget::searchLyricsWikia);
connect(m_ui->resultsTreeView, &QTreeView::doubleClicked, this, &DbQueryWidget::applySpecifiedResults);
connect(m_ui->applyPushButton, &QPushButton::clicked, this, &DbQueryWidget::applySelectedResults);
connect(m_tagEditorWidget, &TagEditorWidget::fileStatusChanged, this, &DbQueryWidget::fileStatusChanged);
@ -133,6 +141,8 @@ SongDescription DbQueryWidget::currentSongDescription() const
void DbQueryWidget::searchMusicBrainz()
{
m_lastSearchAction = m_searchMusicBrainzAction;
// check whether enough search terms are supplied
if (m_ui->titleLineEdit->text().isEmpty() && m_ui->albumLineEdit->text().isEmpty() && m_ui->artistLineEdit->text().isEmpty()) {
m_ui->notificationLabel->setNotificationType(NotificationType::Critical);
@ -155,6 +165,8 @@ void DbQueryWidget::searchMusicBrainz()
void DbQueryWidget::searchLyricsWikia()
{
m_lastSearchAction = m_searchLyricsWikiaAction;
// check whether enough search terms are supplied
if (m_ui->artistLineEdit->text().isEmpty()) {
m_ui->notificationLabel->setNotificationType(NotificationType::Critical);
@ -252,8 +264,8 @@ void DbQueryWidget::showResults()
void DbQueryWidget::setStatus(bool aborted)
{
m_ui->abortPushButton->setVisible(!aborted);
m_ui->searchMusicBrainzPushButton->setVisible(aborted);
m_ui->searchLyricsWikiaPushButton->setVisible(aborted);
m_searchMusicBrainzAction->setEnabled(aborted);
m_searchLyricsWikiaAction->setEnabled(aborted);
m_ui->applyPushButton->setVisible(aborted);
}
@ -658,7 +670,7 @@ bool DbQueryWidget::eventFilter(QObject *obj, QEvent *event)
case QEvent::KeyRelease:
switch (static_cast<QKeyEvent *>(event)->key()) {
case Qt::Key_Return:
searchMusicBrainz();
m_lastSearchAction->trigger();
break;
default:;
}

View File

@ -76,6 +76,9 @@ private:
int m_coverIndex, m_lyricsIndex;
QMenu *m_menu;
QAction *m_insertPresentDataAction;
QAction *m_searchMusicBrainzAction;
QAction *m_searchLyricsWikiaAction;
QAction *m_lastSearchAction;
QPoint m_contextMenuPos;
};

View File

@ -45,6 +45,92 @@
<property name="bottomMargin">
<number>1</number>
</property>
<item>
<widget class="QWidget" name="topWidget" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<layout class="QHBoxLayout" name="bottomLayout">
<property name="spacing">
<number>1</number>
</property>
<property name="leftMargin">
<number>1</number>
</property>
<property name="topMargin">
<number>1</number>
</property>
<property name="rightMargin">
<number>1</number>
</property>
<property name="bottomMargin">
<number>1</number>
</property>
<item>
<widget class="NotificationLabel" name="notificationLabel" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="abortPushButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>Aborts the current query</string>
</property>
<property name="text">
<string>Abort</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="searchPushButton">
<property name="toolTip">
<string>Searches for meta data matching the specified &quot;Search criteria&quot;</string>
</property>
<property name="text">
<string>Search</string>
</property>
<property name="icon">
<iconset theme="edit-find">
<normaloff>.</normaloff>.</iconset>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="applyPushButton">
<property name="enabled">
<bool>false</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>Inserts values of &quot;Fields to be used&quot; from the selected result into the current tag but does not save anything</string>
</property>
<property name="text">
<string>Use row</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="searchGroupBox">
<property name="sizePolicy">
@ -151,25 +237,11 @@
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<widget class="QTreeView" name="resultsTreeView">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="contextMenuPolicy">
<enum>Qt::CustomContextMenu</enum>
</property>
<property name="sizeAdjustPolicy">
<enum>QAbstractScrollArea::AdjustToContentsOnFirstShow</enum>
</property>
</widget>
<widget class="QGroupBox" name="fieldsGroupBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>1</verstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="title">
@ -271,137 +343,20 @@
</item>
</layout>
</widget>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QWidget" name="bottomWidget" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<layout class="QHBoxLayout" name="bottomLayout">
<property name="spacing">
<number>1</number>
</property>
<property name="leftMargin">
<number>1</number>
</property>
<property name="topMargin">
<number>1</number>
</property>
<property name="rightMargin">
<number>1</number>
</property>
<property name="bottomMargin">
<number>1</number>
</property>
<item>
<widget class="NotificationLabel" name="notificationLabel" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="menuPushButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximumSize">
<size>
<width>23</width>
<height>16777215</height>
</size>
</property>
<property name="text">
<string/>
</property>
<property name="flat">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="abortPushButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>Aborts the current query</string>
</property>
<property name="text">
<string>Abort</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="searchMusicBrainzPushButton">
<property name="toolTip">
<string>Searches MusicBrainz for meta data matching the specified &quot;Search criteria&quot;</string>
</property>
<property name="text">
<string>Search
MusicBrainz</string>
</property>
<property name="icon">
<iconset theme="edit-find">
<normaloff>.</normaloff>.</iconset>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="searchLyricsWikiaPushButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>Searches LyricWikia for meta data matching the specified &quot;Search criteria&quot;</string>
</property>
<property name="text">
<string>Search
LyricWikia</string>
</property>
<property name="icon">
<iconset theme="edit-find">
<normaloff>.</normaloff>.</iconset>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="applyPushButton">
<property name="enabled">
<bool>false</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>Inserts values of &quot;Fields to be used&quot; from the selected result into the current tag but does not save anything</string>
</property>
<property name="text">
<string>Use selected
row</string>
</property>
<widget class="QTreeView" name="resultsTreeView">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>1</verstretch>
</sizepolicy>
</property>
<property name="contextMenuPolicy">
<enum>Qt::CustomContextMenu</enum>
</property>
<property name="sizeAdjustPolicy">
<enum>QAbstractScrollArea::AdjustToContentsOnFirstShow</enum>
</property>
</widget>
</widget>
</item>
</layout>