summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorisanae <14251494+isanae@users.noreply.github.com>2019-06-09 17:43:10 -0400
committerisanae <14251494+isanae@users.noreply.github.com>2019-06-15 14:40:40 -0400
commitc8e1b4ab3a51cfe0f39a6f0d78cf0988c380549c (patch)
tree549e563ba7e3dc609d9b92c6ded998c31bdb8a5e /src
parent5fa7fd7fb9f3a8f67e8842420d7a2ad600722119 (diff)
changed the down/up pngs to be slightly offset vertically from what they were, they did not look aligned when next to each other
added status/tooltip/whatsthis strings to new buttons change enabled status of up/down dynamically simplified move() to just move by one
Diffstat (limited to 'src')
-rw-r--r--src/editexecutablesdialog.cpp87
-rw-r--r--src/editexecutablesdialog.h6
-rw-r--r--src/editexecutablesdialog.ui24
-rw-r--r--src/resources/go-down.pngbin874 -> 937 bytes
-rw-r--r--src/resources/go-up.pngbin877 -> 974 bytes
5 files changed, 82 insertions, 35 deletions
diff --git a/src/editexecutablesdialog.cpp b/src/editexecutablesdialog.cpp
index 9747a86f..e2772757 100644
--- a/src/editexecutablesdialog.cpp
+++ b/src/editexecutablesdialog.cpp
@@ -64,7 +64,7 @@ EditExecutablesDialog::EditExecutablesDialog(OrganizerCore& oc, QWidget* parent)
if (ui->list->count() > 0) {
ui->list->item(0)->setSelected(true);
} else {
- updateUI(nullptr);
+ updateUI(nullptr, nullptr);
}
}
@@ -184,23 +184,40 @@ QListWidgetItem* EditExecutablesDialog::createListItem(const Executable& exe)
return newItem;
}
-void EditExecutablesDialog::updateUI(const Executable* e)
+void EditExecutablesDialog::updateUI(
+ const QListWidgetItem* item, const Executable* e)
{
// the ui is currently being set, ignore changes
m_settingUI = true;
if (e) {
setEdits(*e);
- ui->remove->setEnabled(e->isCustom());
} else {
clearEdits();
- ui->remove->setEnabled(false);
}
+ setButtons(item, e);
+
// any changes from now on are from the user
m_settingUI = false;
}
+void EditExecutablesDialog::setButtons(
+ const QListWidgetItem* item, const Executable* e)
+{
+ // add is always enabled
+
+ if (item) {
+ ui->remove->setEnabled(e->isCustom());
+ ui->up->setEnabled(canMove(item, -1));
+ ui->down->setEnabled(canMove(item, +1));
+ } else {
+ ui->remove->setEnabled(false);
+ ui->up->setEnabled(false);
+ ui->down->setEnabled(false);
+ }
+}
+
void EditExecutablesDialog::clearEdits()
{
ui->title->clear();
@@ -348,47 +365,41 @@ void EditExecutablesDialog::save()
}
}
-void EditExecutablesDialog::moveSelection(int by)
+bool EditExecutablesDialog::canMove(const QListWidgetItem* item, int direction)
{
- auto* item = selectedItem();
if (!item) {
- return;
+ return false;
}
- // moving down the list
- while (by > 0) {
- const auto row = ui->list->row(item);
+ if (direction < 0) {
+ // moving up
+ return (ui->list->row(item) > 0);
- if (row >= (ui->list->count() - 1)) {
- break;
- }
-
- ui->list->takeItem(row);
- ui->list->insertItem(row + 1, item);
- item->setSelected(true);
-
- --by;
+ } else if (direction > 0) {
+ // moving down
+ return (ui->list->row(item) < (ui->list->count() - 1));
}
- // moving up the list
- while (by < 0) {
- const auto row = ui->list->row(item);
+ return false;
+}
- if (row <= 0) {
- break;
- }
+void EditExecutablesDialog::move(QListWidgetItem* item, int direction)
+{
+ if (!canMove(item, direction)) {
+ return;
+ }
- ui->list->takeItem(row);
- ui->list->insertItem(row - 1, item);
- item->setSelected(true);
+ const auto row = ui->list->row(item);
- ++by;
- }
+ // removing item
+ ui->list->takeItem(row);
+ ui->list->insertItem(row + (direction > 0 ? 1 : -1), item);
+ item->setSelected(true);
}
void EditExecutablesDialog::on_list_itemSelectionChanged()
{
- updateUI(selectedExe());
+ updateUI(selectedItem(), selectedExe());
}
void EditExecutablesDialog::on_add_clicked()
@@ -448,12 +459,22 @@ void EditExecutablesDialog::on_remove_clicked()
void EditExecutablesDialog::on_up_clicked()
{
- moveSelection(-1);
+ auto* item = selectedItem();
+ if (!item) {
+ return;
+ }
+
+ move(item, -1);
}
void EditExecutablesDialog::on_down_clicked()
{
- moveSelection(+1);
+ auto* item = selectedItem();
+ if (!item) {
+ return;
+ }
+
+ move(item, +1);
}
bool EditExecutablesDialog::isTitleConflicting(const QString& s)
diff --git a/src/editexecutablesdialog.h b/src/editexecutablesdialog.h
index 80ec56df..10a6166f 100644
--- a/src/editexecutablesdialog.h
+++ b/src/editexecutablesdialog.h
@@ -142,11 +142,13 @@ private:
void fillExecutableList();
QListWidgetItem* createListItem(const Executable& exe);
- void updateUI(const Executable* e);
+ void updateUI(const QListWidgetItem* item, const Executable* e);
void clearEdits();
void setEdits(const Executable& e);
+ void setButtons(const QListWidgetItem* item, const Executable* e);
void save();
- void moveSelection(int by);
+ bool canMove(const QListWidgetItem* item, int direction);
+ void move(QListWidgetItem* item, int direction);
void setJarBinary(const QString& binaryName);
std::optional<QString> makeNonConflictingTitle(const QString& prefix);
bool isTitleConflicting(const QString& s);
diff --git a/src/editexecutablesdialog.ui b/src/editexecutablesdialog.ui
index 9801a75c..fb65dbbe 100644
--- a/src/editexecutablesdialog.ui
+++ b/src/editexecutablesdialog.ui
@@ -84,6 +84,9 @@
<property name="toolTip">
<string>Add an executable</string>
</property>
+ <property name="statusTip">
+ <string>Add an executable</string>
+ </property>
<property name="whatsThis">
<string>Add an executable</string>
</property>
@@ -101,6 +104,9 @@
<property name="toolTip">
<string>Remove the selected executable</string>
</property>
+ <property name="statusTip">
+ <string>Remove the selected executable</string>
+ </property>
<property name="whatsThis">
<string>Remove the selected executable</string>
</property>
@@ -115,6 +121,15 @@
</item>
<item>
<widget class="QToolButton" name="up">
+ <property name="toolTip">
+ <string>Move the executable up in the list</string>
+ </property>
+ <property name="statusTip">
+ <string>Move the executable up in the list</string>
+ </property>
+ <property name="whatsThis">
+ <string>Move the executable up in the list</string>
+ </property>
<property name="text">
<string>Move the executable up in the list</string>
</property>
@@ -126,6 +141,15 @@
</item>
<item>
<widget class="QToolButton" name="down">
+ <property name="toolTip">
+ <string>Move the executable down in the list</string>
+ </property>
+ <property name="statusTip">
+ <string>Move the executable down in the list</string>
+ </property>
+ <property name="whatsThis">
+ <string>Move the executable down in the list</string>
+ </property>
<property name="text">
<string>Move the executable down in the list</string>
</property>
diff --git a/src/resources/go-down.png b/src/resources/go-down.png
index af237881..bf0ce4fd 100644
--- a/src/resources/go-down.png
+++ b/src/resources/go-down.png
Binary files differ
diff --git a/src/resources/go-up.png b/src/resources/go-up.png
index b0a0cd72..a4b4e022 100644
--- a/src/resources/go-up.png
+++ b/src/resources/go-up.png
Binary files differ