From ec4f1671b653676af3a44e2fc889c069f2303cfd Mon Sep 17 00:00:00 2001 From: timurhai Date: Wed, 9 Feb 2022 17:11:01 +0300 Subject: [PATCH] afwatch: scroll size preferences option --- afanasy/src/include/afgui.h | 2 ++ afanasy/src/libafqt/qenvironment.cpp | 3 +++ afanasy/src/libafqt/qenvironment.h | 2 ++ afanasy/src/watch/dialog.cpp | 32 ++++++++++++++++++++++++++++ afanasy/src/watch/dialog.h | 4 ++++ afanasy/src/watch/listitems.cpp | 3 +++ afanasy/src/watch/listitems.h | 2 ++ afanasy/src/watch/viewitems.cpp | 1 + docs/changes_log/changes_log.rst | 6 +++++- 9 files changed, 54 insertions(+), 1 deletion(-) diff --git a/afanasy/src/include/afgui.h b/afanasy/src/include/afgui.h index 9eee1bd72..90d4b49b9 100644 --- a/afanasy/src/include/afgui.h +++ b/afanasy/src/include/afgui.h @@ -8,6 +8,8 @@ namespace AFGUI const int JEDI = 1; const int SITH = 2; + const int SCROLL_SIZE = 32; + const int SAVEPREFSONEXIT = 1; const int SAVEWNDRECTS = 1; const int SAVEGUI = 0; diff --git a/afanasy/src/libafqt/qenvironment.cpp b/afanasy/src/libafqt/qenvironment.cpp index 970e029dd..daa36297e 100644 --- a/afanasy/src/libafqt/qenvironment.cpp +++ b/afanasy/src/libafqt/qenvironment.cpp @@ -23,6 +23,8 @@ AttrNumber QEnvironment::level("level", "UI Level", AFGUI::PADAWAN); Attr QEnvironment::theme("theme", "Theme", AFGUI::THEME ); +AttrNumber QEnvironment::scroll_step("scroll_step", "Scroll Step", AFGUI::SCROLL_SIZE); + Attr QEnvironment::image_back( "image_back", "Items Background", ""); Attr QEnvironment::image_border_top( "image_border_top", "Border Top", ""); Attr QEnvironment::image_border_topleft( "image_border_topleft", "Border Top Left", ""); @@ -152,6 +154,7 @@ QEnvironment::QEnvironment( const QString & i_name) ms_attrs_prefs.append( &level ); ms_attrs_prefs.append( &theme ); + ms_attrs_prefs.append(&scroll_step ); ms_attrs_prefs.append( &savePrefsOnExit ); ms_attrs_prefs.append( &saveWndRectsOnExit ); ms_attrs_prefs.append( &saveGUIOnExit ); diff --git a/afanasy/src/libafqt/qenvironment.h b/afanasy/src/libafqt/qenvironment.h index fa00c4e21..ca35c33ba 100644 --- a/afanasy/src/libafqt/qenvironment.h +++ b/afanasy/src/libafqt/qenvironment.h @@ -40,6 +40,8 @@ class afqt::QEnvironment static Attr theme; + static AttrNumber scroll_step; + static Attr image_back; static Attr image_border_top; static Attr image_border_topleft; diff --git a/afanasy/src/watch/dialog.cpp b/afanasy/src/watch/dialog.cpp index 515409161..f127d9b55 100644 --- a/afanasy/src/watch/dialog.cpp +++ b/afanasy/src/watch/dialog.cpp @@ -47,6 +47,8 @@ int Dialog::ms_size_border_bot = 25; int Dialog::ms_size_border_left = 65; int Dialog::ms_size_border_right = 75; +QVector Dialog::ms_scroll_steps = {-1, 16, 32, 64}; + Dialog::Dialog(): m_connected(false), m_monitorType( Watch::WNONE), @@ -262,6 +264,28 @@ void Dialog::showMenuPrefs() m_prefsMenu->clear(); QAction * action; + QMenu * scroll_step_menu = new QMenu("Set Scroll Step"); + m_prefsMenu->addMenu(scroll_step_menu); + + for (int i = 0; i < ms_scroll_steps.size(); i++) + { + int step = ms_scroll_steps[i]; + QString label = QString("%1 Pixels").arg(step); + if (i == 0) + label = "By Item Size."; + + ActionId * action_id = new ActionId(step, label, scroll_step_menu); + action_id->setCheckable(true); + action_id->setChecked(afqt::QEnvironment::scroll_step.n == step); + connect(action_id, SIGNAL(triggeredId(int)), this, SLOT(actScrollStep(int))); + scroll_step_menu->addAction(action_id); + + if (i == 0) + scroll_step_menu->addSeparator(); + } + + m_prefsMenu->addSeparator(); + action = new QAction( "Save Prefs on Exit", m_prefsMenu); action->setCheckable( true); action->setChecked( afqt::QEnvironment::savePrefsOnExit.n != 0); @@ -717,6 +741,14 @@ void Dialog::actGuiTheme( QString theme) Watch::displayError(QString("Failed to load '%1' theme").arg( theme)); } +void Dialog::actScrollStep(int i_step) +{ + afqt::QEnvironment::scroll_step.n = i_step; + + if (m_listitems) + m_listitems->setScrollStep(i_step); +} + void Dialog::reloadImages() { Watch::loadImage( m_img_top, afqt::QEnvironment::image_border_top.str ); diff --git a/afanasy/src/watch/dialog.h b/afanasy/src/watch/dialog.h index 0745f3b31..0af4bd8ae 100644 --- a/afanasy/src/watch/dialog.h +++ b/afanasy/src/watch/dialog.h @@ -77,6 +77,7 @@ private slots: void actShowOfflineNoise(); void actGuiTheme( QString theme); void actGuiLevel( int i_level); + void actScrollStep(int i_step); void actShowDocs(); void actShowForum(); @@ -142,4 +143,7 @@ private slots: static int ms_size_border_bot; static int ms_size_border_left; static int ms_size_border_right; + + static QVector ms_scroll_steps; + }; diff --git a/afanasy/src/watch/listitems.cpp b/afanasy/src/watch/listitems.cpp index a89bd818c..fee3f6836 100644 --- a/afanasy/src/watch/listitems.cpp +++ b/afanasy/src/watch/listitems.cpp @@ -18,6 +18,7 @@ #include #include #include +#include #include #define AFOUTPUT @@ -156,6 +157,8 @@ ListItems::~ListItems() int ListItems::count() const { return m_model->count();} +void ListItems::setScrollStep(int i_step) {m_view->verticalScrollBar()->setSingleStep(i_step);} + bool ListItems::mousePressed(QMouseEvent * i_event) { QModelIndex index = m_view->indexAt(i_event->pos()); diff --git a/afanasy/src/watch/listitems.h b/afanasy/src/watch/listitems.h index c1169ebf8..8ff213961 100644 --- a/afanasy/src/watch/listitems.h +++ b/afanasy/src/watch/listitems.h @@ -63,6 +63,8 @@ Q_OBJECT // Not called on list dtor. virtual void v_itemToBeDeleted(Item * i_item); + void setScrollStep(int i_step); + public slots: void repaintItems(); void deleteAllItems(); diff --git a/afanasy/src/watch/viewitems.cpp b/afanasy/src/watch/viewitems.cpp index 018104296..8b4e71d0b 100644 --- a/afanasy/src/watch/viewitems.cpp +++ b/afanasy/src/watch/viewitems.cpp @@ -45,6 +45,7 @@ ViewItems::ViewItems( ListItems * parent): setHorizontalScrollMode(ScrollPerPixel); setVerticalScrollMode(ScrollPerPixel); + verticalScrollBar()->setSingleStep(afqt::QEnvironment::scroll_step.n); setSelectionRectVisible( true); setSelectionMode( QAbstractItemView::ExtendedSelection); diff --git a/docs/changes_log/changes_log.rst b/docs/changes_log/changes_log.rst index fbdc15a36..d24a87842 100644 --- a/docs/changes_log/changes_log.rst +++ b/docs/changes_log/changes_log.rst @@ -23,7 +23,11 @@ v3.2.2 - Afanasy config: Parameter of a string array type can be overridden by command arguments or environment by a string contains a comma separated items. -- AfWatch: Task window uses mono-space font for task output and log. +- AfWatch + + - Task window uses mono-space font for task output and log. + + - Scroll step size preferences option. Later scroll size was only by item height. - Houdini Afanasy ROP: