Skip to content

Commit

Permalink
Merge pull request #5385 from titan73/master
Browse files Browse the repository at this point in the history
gui: Add option to map mouse wheel to zoom in/out by default in layout view
  • Loading branch information
maliberty authored Jul 16, 2024
2 parents ee0b965 + 8d5207a commit babe155
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 7 deletions.
4 changes: 3 additions & 1 deletion src/gui/src/layoutTabs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ LayoutTabs::LayoutTabs(Options* options,
Gui* gui,
std::function<bool(void)> usingDBU,
std::function<bool(void)> showRulerAsEuclidian,
std::function<bool(void)> default_mouse_wheel_zoom,
QWidget* parent)
: QTabWidget(parent),
options_(options),
Expand All @@ -58,6 +59,7 @@ LayoutTabs::LayoutTabs(Options* options,
gui_(gui),
usingDBU_(std::move(usingDBU)),
showRulerAsEuclidian_(std::move(showRulerAsEuclidian)),
default_mouse_wheel_zoom_(std::move(default_mouse_wheel_zoom)),
logger_(nullptr)
{
setTabBarAutoHide(true);
Expand Down Expand Up @@ -92,7 +94,7 @@ void LayoutTabs::blockLoaded(odb::dbBlock* block)
if (command_executing_) {
viewer->commandAboutToExecute();
}
auto scroll = new LayoutScroll(viewer, this);
auto scroll = new LayoutScroll(viewer, default_mouse_wheel_zoom_, this);
viewer->blockLoaded(block);

auto tech = block->getTech();
Expand Down
2 changes: 2 additions & 0 deletions src/gui/src/layoutTabs.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class LayoutTabs : public QTabWidget
Gui* gui,
std::function<bool(void)> usingDBU,
std::function<bool(void)> showRulerAsEuclidian,
std::function<bool(void)> default_mouse_wheel_zoom,
QWidget* parent = nullptr);

LayoutViewer* getCurrent() const { return current_viewer_; }
Expand Down Expand Up @@ -140,6 +141,7 @@ class LayoutTabs : public QTabWidget
Gui* gui_;
std::function<bool(void)> usingDBU_;
std::function<bool(void)> showRulerAsEuclidian_;
std::function<bool(void)> default_mouse_wheel_zoom_;
utl::Logger* logger_;
bool command_executing_ = false;

Expand Down
16 changes: 12 additions & 4 deletions src/gui/src/layoutViewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2426,8 +2426,14 @@ void LayoutViewer::executionPaused()
}

////// LayoutScroll ///////
LayoutScroll::LayoutScroll(LayoutViewer* viewer, QWidget* parent)
: QScrollArea(parent), viewer_(viewer), scrolling_with_cursor_(false)
LayoutScroll::LayoutScroll(
LayoutViewer* viewer,
const std::function<bool(void)>& default_mouse_wheel_zoom,
QWidget* parent)
: QScrollArea(parent),
default_mouse_wheel_zoom_(std::move(default_mouse_wheel_zoom)),
viewer_(viewer),
scrolling_with_cursor_(false)
{
setWidgetResizable(false);
setWidget(viewer);
Expand All @@ -2451,10 +2457,12 @@ void LayoutScroll::scrollContentsBy(int dx, int dy)
widget()->update();
}

// Handles zoom in/out on ctrl-wheel
// Handles zoom in/out on ctrl-wheel when option mouse_wheel_zoom is not set and
// vice-versa
void LayoutScroll::wheelEvent(QWheelEvent* event)
{
if (!event->modifiers().testFlag(Qt::ControlModifier)) {
if (default_mouse_wheel_zoom_()
== event->modifiers().testFlag(Qt::ControlModifier)) {
QScrollArea::wheelEvent(event);
return;
}
Expand Down
6 changes: 4 additions & 2 deletions src/gui/src/layoutViewer.h
Original file line number Diff line number Diff line change
Expand Up @@ -463,8 +463,9 @@ class LayoutScroll : public QScrollArea
{
Q_OBJECT
public:
LayoutScroll(LayoutViewer* viewer, QWidget* parent = 0);

LayoutScroll(LayoutViewer* viewer,
const std::function<bool(void)>& default_mouse_wheel_zoom,
QWidget* parent = nullptr);
bool isScrollingWithCursor();
signals:
// indicates that the viewport (visible area of the layout) has changed
Expand All @@ -481,6 +482,7 @@ class LayoutScroll : public QScrollArea
bool eventFilter(QObject* object, QEvent* event) override;

private:
std::function<bool(void)> default_mouse_wheel_zoom_;
LayoutViewer* viewer_;

bool scrolling_with_cursor_;
Expand Down
11 changes: 11 additions & 0 deletions src/gui/src/mainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ MainWindow::MainWindow(QWidget* parent)
Gui::get(),
[this]() -> bool { return show_dbu_->isChecked(); },
[this]() -> bool { return default_ruler_style_->isChecked(); },
[this]() -> bool { return default_mouse_wheel_zoom_->isChecked(); },
this)),
selection_browser_(
new SelectHighlightWindow(selected_, highlighted_, this)),
Expand Down Expand Up @@ -390,6 +391,9 @@ MainWindow::MainWindow(QWidget* parent)
default_ruler_style_->setChecked(
settings.value("ruler_style", default_ruler_style_->isChecked())
.toBool());
default_mouse_wheel_zoom_->setChecked(
settings.value("mouse_wheel_zoom", default_mouse_wheel_zoom_->isChecked())
.toBool());
script_->readSettings(&settings);
controls_->readSettings(&settings);
timing_widget_->readSettings(&settings);
Expand Down Expand Up @@ -584,6 +588,11 @@ void MainWindow::createActions()
default_ruler_style_->setCheckable(true);
default_ruler_style_->setChecked(true);

default_mouse_wheel_zoom_
= new QAction("Mouse wheel mapped to zoom by default", this);
default_mouse_wheel_zoom_->setCheckable(true);
default_mouse_wheel_zoom_->setChecked(false);

font_ = new QAction("Application font", this);

global_connect_ = new QAction("Global connect", this);
Expand Down Expand Up @@ -696,6 +705,7 @@ void MainWindow::createMenus()
option_menu->addAction(hide_option_);
option_menu->addAction(show_dbu_);
option_menu->addAction(default_ruler_style_);
option_menu->addAction(default_mouse_wheel_zoom_);
option_menu->addAction(font_);

menuBar()->addAction(help_);
Expand Down Expand Up @@ -1350,6 +1360,7 @@ void MainWindow::saveSettings()
settings.setValue("check_exit", hide_option_->isChecked());
settings.setValue("use_dbu", show_dbu_->isChecked());
settings.setValue("ruler_style", default_ruler_style_->isChecked());
settings.setValue("mouse_wheel_zoom", default_mouse_wheel_zoom_->isChecked());
script_->writeSettings(&settings);
controls_->writeSettings(&settings);
timing_widget_->writeSettings(&settings);
Expand Down
1 change: 1 addition & 0 deletions src/gui/src/mainWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,7 @@ class MainWindow : public QMainWindow, public ord::OpenRoadObserver
QAction* build_ruler_;
QAction* show_dbu_;
QAction* default_ruler_style_;
QAction* default_mouse_wheel_zoom_;
QAction* font_;
QAction* global_connect_;

Expand Down

0 comments on commit babe155

Please sign in to comment.