Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option to display history in reverse order #150

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 69 additions & 14 deletions src/qlippermodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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())
{
Expand Down
4 changes: 4 additions & 0 deletions src/qlipperpreferences.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions src/qlipperpreferences.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 2 additions & 0 deletions src/qlipperpreferencesdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());

Expand Down Expand Up @@ -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());

Expand Down
124 changes: 67 additions & 57 deletions src/qlipperpreferencesdialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,17 @@
<string>Preferences</string>
</attribute>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLabel" name="label">
<item row="10" column="0">
<widget class="QCheckBox" name="confirmOnClear">
<property name="text">
<string>Clipboard Entries Count:</string>
<string>Confirm Clear History</string>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QKeySequenceWidget" name="shortcutWidget" native="true">
<property name="toolTip">
<string>Change global keyboard shortcut to invoke the menu on screen</string>
</property>
</widget>
</item>
Expand Down Expand Up @@ -97,7 +104,14 @@
</property>
</widget>
</item>
<item row="2" column="0" colspan="2">
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Clipboard Entries Count:</string>
</property>
</widget>
</item>
<item row="3" column="0" colspan="2">
<widget class="QCheckBox" name="trimCheckBox">
<property name="toolTip">
<string>Useful for bigger text blocks copied for example from dummy terminals (minicom, etc.)</string>
Expand All @@ -107,21 +121,7 @@
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="keyboardShortcutLabel">
<property name="text">
<string>Keyboard Shortcut:</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QKeySequenceWidget" name="shortcutWidget" native="true">
<property name="toolTip">
<string>Change global keyboard shortcut to invoke the menu on screen</string>
</property>
</widget>
</item>
<item row="4" column="0">
<item row="5" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Tray icon image:</string>
Expand All @@ -131,23 +131,7 @@
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QToolButton" name="buttonIconImage">
<property name="text">
<string/>
</property>
<property name="iconSize">
<size>
<width>20</width>
<height>20</height>
</size>
</property>
<property name="popupMode">
<enum>QToolButton::InstantPopup</enum>
</property>
</widget>
</item>
<item row="5" column="0" colspan="2">
<item row="6" column="0" colspan="2">
<widget class="QCheckBox" name="platformExtensionsCheckBox">
<property name="toolTip">
<string>Use clipboard extensions (X11 Selections, OS X Find Buffer) when it's supported</string>
Expand All @@ -157,7 +141,27 @@
</property>
</widget>
</item>
<item row="6" column="0" colspan="2">
<item row="9" column="0" colspan="2">
<widget class="QCheckBox" name="synchronizeHistory">
<property name="text">
<string>Synchronize history to storage instantly</string>
</property>
</widget>
</item>
<item row="11" column="0" colspan="2">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>96</height>
</size>
</property>
</spacer>
</item>
<item row="7" column="0" colspan="2">
<widget class="QComboBox" name="synchronizePSE">
<item>
<property name="text">
Expand All @@ -176,37 +180,43 @@
</item>
</widget>
</item>
<item row="7" column="0" colspan="2">
<widget class="QCheckBox" name="clearItemsOnExit">
<item row="5" column="1">
<widget class="QToolButton" name="buttonIconImage">
<property name="text">
<string>Clear Items on Exit</string>
<string/>
</property>
<property name="iconSize">
<size>
<width>20</width>
<height>20</height>
</size>
</property>
<property name="popupMode">
<enum>QToolButton::InstantPopup</enum>
</property>
</widget>
</item>
<item row="8" column="0" colspan="2">
<widget class="QCheckBox" name="synchronizeHistory">
<item row="4" column="0">
<widget class="QLabel" name="keyboardShortcutLabel">
<property name="text">
<string>Synchronize history to storage instantly</string>
<string>Keyboard Shortcut:</string>
</property>
</widget>
</item>
<item row="10" column="0" colspan="2">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>96</height>
</size>
<item row="2" column="0">
<widget class="QCheckBox" name="clearItemsOnExit">
<property name="text">
<string>Clear Items on Exit</string>
</property>
</spacer>
</widget>
</item>
<item row="9" column="0">
<widget class="QCheckBox" name="confirmOnClear">
<item row="2" column="1">
<widget class="QCheckBox" name="reverseOrder">
<property name="toolTip">
<string>Newly copied data appears at end of the menu</string>
</property>
<property name="text">
<string>Confirm Clear History</string>
<string>Reverse order</string>
</property>
</widget>
</item>
Expand Down