diff --git a/src/qlippermodel.cpp b/src/qlippermodel.cpp
index 1a08565..fcb0af0 100644
--- a/src/qlippermodel.cpp
+++ b/src/qlippermodel.cpp
@@ -66,6 +66,13 @@ QlipperModel::~QlipperModel()
void QlipperModel::resetPreferences()
{
+ // If sticky items is empty, code will crash in Debug mode for unknown reason
+ // It will not crash in Release mode
+ if (m_sticky.count() == 0)
+ {
+ return;
+ }
+
beginRemoveRows(QModelIndex(), 0, m_sticky.count() - 1);
m_sticky.clear();
endRemoveRows();
@@ -166,35 +173,83 @@ void QlipperModel::clipboard_changed(QClipboard::Mode mode)
int ix = m_dynamic.indexOf(item);
if (ix == -1)
{
+ bool reverseOrder = QlipperPreferences::Instance()->reverseOrder();
+
const int sticky_count = m_sticky.count();
beginInsertRows(QModelIndex(), sticky_count, sticky_count);
- m_dynamic.prepend(item);
+ if (reverseOrder)
+ {
+ m_dynamic.append(item);
+ }
+ else
+ {
+ m_dynamic.prepend(item);
+ }
endInsertRows();
const int max_history = QlipperPreferences::Instance()->historyCount();
if (m_dynamic.count() > max_history)
{
- beginRemoveRows(QModelIndex(), sticky_count + max_history - 1, sticky_count + m_dynamic.count() - 1);
- m_dynamic.erase(m_dynamic.begin() + (max_history - 1), m_dynamic.end());
- endRemoveRows();
+ if (reverseOrder)
+ {
+ auto removeRowsBeginPosition = sticky_count;
+ auto removeRowsEndPosition = removeRowsBeginPosition + (m_dynamic.count() - max_history);
+ beginRemoveRows(QModelIndex(), removeRowsBeginPosition, removeRowsEndPosition);
+ auto dataBeginPosition = m_dynamic.begin();
+ auto dataEndPosition = dataBeginPosition + (m_dynamic.count() - max_history);
+ m_dynamic.erase(dataBeginPosition, dataEndPosition);
+ endRemoveRows();
+ }
+ else
+ {
+ auto removeRowsBeginPosition = sticky_count + max_history - 1;
+ auto removeRowsEndPosition = sticky_count + m_dynamic.count() - 1;
+ beginRemoveRows(QModelIndex(), removeRowsBeginPosition, removeRowsEndPosition);
+ auto beginPosition = m_dynamic.begin() + (max_history - 1);
+ auto endPosition = m_dynamic.end();
+ m_dynamic.erase(beginPosition, endPosition);
+ endRemoveRows();
+ }
}
- ix = 0;
+ ix = reverseOrder
+ ? m_dynamic.count() - 1
+ : 0;
}
setCurrentDynamic(ix);
}
void QlipperModel::setCurrentDynamic(int ix)
{
- // move if not already on top
- if (ix != 0)
+ bool reverseOrder = QlipperPreferences::Instance()->reverseOrder();
+ const int sticky_count = m_sticky.count();
+ auto m_dynamic_count = m_dynamic.count();
+
+ if (reverseOrder)
{
- const int sticky_count = m_sticky.count();
- beginMoveRows(QModelIndex(), sticky_count + ix, sticky_count + ix, QModelIndex(), sticky_count);
- m_dynamic.move(ix, 0);
- endMoveRows();
- }
+ auto m_dynamic_lastIndex = m_dynamic_count - 1;
+
+ // move if not already on end
+ if (ix != m_dynamic_lastIndex)
+ {
+ beginMoveRows(QModelIndex(), sticky_count + ix, sticky_count + ix, QModelIndex(), sticky_count + m_dynamic_count);
+ m_dynamic.move(ix, m_dynamic_lastIndex);
+ endMoveRows();
+ }
- m_currentIndex = index(m_sticky.count());
- m_network->sendData(m_dynamic.at(0).content());
+ m_currentIndex = index(m_sticky.count() + m_dynamic_lastIndex);
+ m_network->sendData(m_dynamic.at(m_dynamic_lastIndex).content());
+ }
+ else
+ {
+ // move if not already on top
+ if (ix != 0)
+ {
+ beginMoveRows(QModelIndex(), sticky_count + ix, sticky_count + ix, QModelIndex(), sticky_count);
+ m_dynamic.move(ix, 0);
+ endMoveRows();
+ }
+ m_currentIndex = index(m_sticky.count());
+ m_network->sendData(m_dynamic.at(0).content());
+ }
if (QlipperPreferences::Instance()->synchronizeHistory())
{
diff --git a/src/qlipperpreferences.cpp b/src/qlipperpreferences.cpp
index 09b17e7..9e02638 100755
--- a/src/qlipperpreferences.cpp
+++ b/src/qlipperpreferences.cpp
@@ -223,6 +223,10 @@ bool QlipperPreferences::confirmOnClear() const
return value("confirmClear", true).toBool();
}
+bool QlipperPreferences::reverseOrder() const{
+ return value("reverseOrder", false).toBool();
+}
+
bool QlipperPreferences::networkSend() const
{
return value("networkSend", false).toBool();
diff --git a/src/qlipperpreferences.h b/src/qlipperpreferences.h
index 4823865..cee5be7 100755
--- a/src/qlipperpreferences.h
+++ b/src/qlipperpreferences.h
@@ -55,6 +55,7 @@ class QlipperPreferences : public QSettings
bool platformExtensions() const;
PSESynchronization synchronizePSE() const;
bool clearItemsOnExit() const;
+ bool reverseOrder() const;
bool synchronizeHistory() const;
bool confirmOnClear() const;
diff --git a/src/qlipperpreferencesdialog.cpp b/src/qlipperpreferencesdialog.cpp
index 59ea849..7d39010 100755
--- a/src/qlipperpreferencesdialog.cpp
+++ b/src/qlipperpreferencesdialog.cpp
@@ -42,6 +42,7 @@ QlipperPreferencesDialog::QlipperPreferencesDialog(QWidget *parent) :
synchronizePSE->setEnabled(pse);
synchronizePSE->setCurrentIndex(s->synchronizePSE());
clearItemsOnExit->setChecked(s->clearItemsOnExit());
+ reverseOrder->setChecked(s->reverseOrder());
synchronizeHistory->setChecked(s->synchronizeHistory());
confirmOnClear->setChecked(s->confirmOnClear());
@@ -106,6 +107,7 @@ void QlipperPreferencesDialog::accept()
s->setValue("synchronizePSE", synchronizePSE->currentIndex());
s->setValue("shortcut", shortcutWidget->keySequence().toString());
s->setValue("clearItemsOnExit", clearItemsOnExit->isChecked());
+ s->setValue("reverseOrder", reverseOrder->isChecked());
s->setValue("synchronizeHistory", synchronizeHistory->isChecked());
s->setValue("confirmClear", confirmOnClear->isChecked());
diff --git a/src/qlipperpreferencesdialog.ui b/src/qlipperpreferencesdialog.ui
index 4285263..9087ced 100755
--- a/src/qlipperpreferencesdialog.ui
+++ b/src/qlipperpreferencesdialog.ui
@@ -42,10 +42,17 @@
Preferences
- -
-
+
-
+
- Clipboard Entries Count:
+ Confirm Clear History
+
+
+
+ -
+
+
+ Change global keyboard shortcut to invoke the menu on screen
@@ -97,7 +104,14 @@
- -
+
-
+
+
+ Clipboard Entries Count:
+
+
+
+ -
Useful for bigger text blocks copied for example from dummy terminals (minicom, etc.)
@@ -107,21 +121,7 @@
- -
-
-
- Keyboard Shortcut:
-
-
-
- -
-
-
- Change global keyboard shortcut to invoke the menu on screen
-
-
-
- -
+
-
Tray icon image:
@@ -131,23 +131,7 @@
- -
-
-
-
-
-
-
- 20
- 20
-
-
-
- QToolButton::InstantPopup
-
-
-
- -
+
-
Use clipboard extensions (X11 Selections, OS X Find Buffer) when it's supported
@@ -157,7 +141,27 @@
- -
+
-
+
+
+ Synchronize history to storage instantly
+
+
+
+ -
+
+
+ Qt::Vertical
+
+
+
+ 20
+ 96
+
+
+
+
+ -
-
@@ -176,37 +180,43 @@
- -
-
+
-
+
- Clear Items on Exit
+
+
+
+
+ 20
+ 20
+
+
+
+ QToolButton::InstantPopup
- -
-
+
-
+
- Synchronize history to storage instantly
+ Keyboard Shortcut:
- -
-
-
- Qt::Vertical
-
-
-
- 20
- 96
-
+
-
+
+
+ Clear Items on Exit
-
+
- -
-
+
-
+
+
+ Newly copied data appears at end of the menu
+
- Confirm Clear History
+ Reverse order