Skip to content

Commit a2be245

Browse files
committed
gui: Add option to map mouse wheel to zoom in/out by default in layout view.
1 parent ee0b965 commit a2be245

File tree

6 files changed

+28
-7
lines changed

6 files changed

+28
-7
lines changed

src/gui/src/layoutTabs.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ LayoutTabs::LayoutTabs(Options* options,
4848
Gui* gui,
4949
std::function<bool(void)> usingDBU,
5050
std::function<bool(void)> showRulerAsEuclidian,
51+
std::function<bool(void)> default_mouse_wheel_zoom,
5152
QWidget* parent)
5253
: QTabWidget(parent),
5354
options_(options),
@@ -58,6 +59,7 @@ LayoutTabs::LayoutTabs(Options* options,
5859
gui_(gui),
5960
usingDBU_(std::move(usingDBU)),
6061
showRulerAsEuclidian_(std::move(showRulerAsEuclidian)),
62+
default_mouse_wheel_zoom_(std::move(default_mouse_wheel_zoom)),
6163
logger_(nullptr)
6264
{
6365
setTabBarAutoHide(true);
@@ -92,7 +94,7 @@ void LayoutTabs::blockLoaded(odb::dbBlock* block)
9294
if (command_executing_) {
9395
viewer->commandAboutToExecute();
9496
}
95-
auto scroll = new LayoutScroll(viewer, this);
97+
auto scroll = new LayoutScroll(viewer, default_mouse_wheel_zoom_, this);
9698
viewer->blockLoaded(block);
9799

98100
auto tech = block->getTech();

src/gui/src/layoutTabs.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ class LayoutTabs : public QTabWidget
6060
Gui* gui,
6161
std::function<bool(void)> usingDBU,
6262
std::function<bool(void)> showRulerAsEuclidian,
63+
std::function<bool(void)> default_mouse_wheel_zoom,
6364
QWidget* parent = nullptr);
6465

6566
LayoutViewer* getCurrent() const { return current_viewer_; }
@@ -140,6 +141,7 @@ class LayoutTabs : public QTabWidget
140141
Gui* gui_;
141142
std::function<bool(void)> usingDBU_;
142143
std::function<bool(void)> showRulerAsEuclidian_;
144+
std::function<bool(void)> default_mouse_wheel_zoom_;
143145
utl::Logger* logger_;
144146
bool command_executing_ = false;
145147

src/gui/src/layoutViewer.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2426,8 +2426,12 @@ void LayoutViewer::executionPaused()
24262426
}
24272427

24282428
////// LayoutScroll ///////
2429-
LayoutScroll::LayoutScroll(LayoutViewer* viewer, QWidget* parent)
2430-
: QScrollArea(parent), viewer_(viewer), scrolling_with_cursor_(false)
2429+
LayoutScroll::LayoutScroll(LayoutViewer* viewer,
2430+
const std::function<bool(void)>& default_mouse_wheel_zoom,
2431+
QWidget* parent)
2432+
: QScrollArea(parent),
2433+
default_mouse_wheel_zoom_(std::move(default_mouse_wheel_zoom)),
2434+
viewer_(viewer), scrolling_with_cursor_(false)
24312435
{
24322436
setWidgetResizable(false);
24332437
setWidget(viewer);
@@ -2451,10 +2455,10 @@ void LayoutScroll::scrollContentsBy(int dx, int dy)
24512455
widget()->update();
24522456
}
24532457

2454-
// Handles zoom in/out on ctrl-wheel
2458+
// Handles zoom in/out on ctrl-wheel when option mouse_wheel_zoom is not set and vice-versa
24552459
void LayoutScroll::wheelEvent(QWheelEvent* event)
24562460
{
2457-
if (!event->modifiers().testFlag(Qt::ControlModifier)) {
2461+
if (default_mouse_wheel_zoom_() == event->modifiers().testFlag(Qt::ControlModifier)) {
24582462
QScrollArea::wheelEvent(event);
24592463
return;
24602464
}

src/gui/src/layoutViewer.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -463,8 +463,9 @@ class LayoutScroll : public QScrollArea
463463
{
464464
Q_OBJECT
465465
public:
466-
LayoutScroll(LayoutViewer* viewer, QWidget* parent = 0);
467-
466+
LayoutScroll(LayoutViewer* viewer,
467+
const std::function<bool(void)>& default_mouse_wheel_zoom,
468+
QWidget* parent = 0);
468469
bool isScrollingWithCursor();
469470
signals:
470471
// indicates that the viewport (visible area of the layout) has changed
@@ -481,6 +482,7 @@ class LayoutScroll : public QScrollArea
481482
bool eventFilter(QObject* object, QEvent* event) override;
482483

483484
private:
485+
std::function<bool(void)> default_mouse_wheel_zoom_;
484486
LayoutViewer* viewer_;
485487

486488
bool scrolling_with_cursor_;

src/gui/src/mainWindow.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ MainWindow::MainWindow(QWidget* parent)
9595
Gui::get(),
9696
[this]() -> bool { return show_dbu_->isChecked(); },
9797
[this]() -> bool { return default_ruler_style_->isChecked(); },
98+
[this]() -> bool { return default_mouse_wheel_zoom_->isChecked(); },
9899
this)),
99100
selection_browser_(
100101
new SelectHighlightWindow(selected_, highlighted_, this)),
@@ -390,6 +391,9 @@ MainWindow::MainWindow(QWidget* parent)
390391
default_ruler_style_->setChecked(
391392
settings.value("ruler_style", default_ruler_style_->isChecked())
392393
.toBool());
394+
default_mouse_wheel_zoom_->setChecked(
395+
settings.value("mouse_wheel_zoom", default_mouse_wheel_zoom_->isChecked())
396+
.toBool());
393397
script_->readSettings(&settings);
394398
controls_->readSettings(&settings);
395399
timing_widget_->readSettings(&settings);
@@ -584,6 +588,10 @@ void MainWindow::createActions()
584588
default_ruler_style_->setCheckable(true);
585589
default_ruler_style_->setChecked(true);
586590

591+
default_mouse_wheel_zoom_ = new QAction("Mouse wheel mapped to zoom by default", this);
592+
default_mouse_wheel_zoom_->setCheckable(true);
593+
default_mouse_wheel_zoom_->setChecked(false);
594+
587595
font_ = new QAction("Application font", this);
588596

589597
global_connect_ = new QAction("Global connect", this);
@@ -696,6 +704,7 @@ void MainWindow::createMenus()
696704
option_menu->addAction(hide_option_);
697705
option_menu->addAction(show_dbu_);
698706
option_menu->addAction(default_ruler_style_);
707+
option_menu->addAction(default_mouse_wheel_zoom_);
699708
option_menu->addAction(font_);
700709

701710
menuBar()->addAction(help_);
@@ -1350,6 +1359,7 @@ void MainWindow::saveSettings()
13501359
settings.setValue("check_exit", hide_option_->isChecked());
13511360
settings.setValue("use_dbu", show_dbu_->isChecked());
13521361
settings.setValue("ruler_style", default_ruler_style_->isChecked());
1362+
settings.setValue("mouse_wheel_zoom", default_mouse_wheel_zoom_->isChecked());
13531363
script_->writeSettings(&settings);
13541364
controls_->writeSettings(&settings);
13551365
timing_widget_->writeSettings(&settings);

src/gui/src/mainWindow.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,7 @@ class MainWindow : public QMainWindow, public ord::OpenRoadObserver
331331
QAction* build_ruler_;
332332
QAction* show_dbu_;
333333
QAction* default_ruler_style_;
334+
QAction* default_mouse_wheel_zoom_;
334335
QAction* font_;
335336
QAction* global_connect_;
336337

0 commit comments

Comments
 (0)