Skip to content

Commit

Permalink
afwatch: scroll size preferences option
Browse files Browse the repository at this point in the history
  • Loading branch information
timurhai committed Feb 9, 2022
1 parent f9de29d commit ec4f167
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 1 deletion.
2 changes: 2 additions & 0 deletions afanasy/src/include/afgui.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions afanasy/src/libafqt/qenvironment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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", "");
Expand Down Expand Up @@ -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 );
Expand Down
2 changes: 2 additions & 0 deletions afanasy/src/libafqt/qenvironment.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
32 changes: 32 additions & 0 deletions afanasy/src/watch/dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int> Dialog::ms_scroll_steps = {-1, 16, 32, 64};

Dialog::Dialog():
m_connected(false),
m_monitorType( Watch::WNONE),
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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 );
Expand Down
4 changes: 4 additions & 0 deletions afanasy/src/watch/dialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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<int> ms_scroll_steps;

};
3 changes: 3 additions & 0 deletions afanasy/src/watch/listitems.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <QtGui/QKeyEvent>
#include <QBoxLayout>
#include <QLabel>
#include <QScrollBar>
#include <QSplitter>

#define AFOUTPUT
Expand Down Expand Up @@ -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());
Expand Down
2 changes: 2 additions & 0 deletions afanasy/src/watch/listitems.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions afanasy/src/watch/viewitems.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ ViewItems::ViewItems( ListItems * parent):

setHorizontalScrollMode(ScrollPerPixel);
setVerticalScrollMode(ScrollPerPixel);
verticalScrollBar()->setSingleStep(afqt::QEnvironment::scroll_step.n);

setSelectionRectVisible( true);
setSelectionMode( QAbstractItemView::ExtendedSelection);
Expand Down
6 changes: 5 additions & 1 deletion docs/changes_log/changes_log.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down

0 comments on commit ec4f167

Please sign in to comment.