diff --git a/src/app/puzzle/dialogs/configpages/puzzlepreferencesconfigurationpage.cpp b/src/app/puzzle/dialogs/configpages/puzzlepreferencesconfigurationpage.cpp index 1d9e8ecef..958240881 100644 --- a/src/app/puzzle/dialogs/configpages/puzzlepreferencesconfigurationpage.cpp +++ b/src/app/puzzle/dialogs/configpages/puzzlepreferencesconfigurationpage.cpp @@ -32,6 +32,7 @@ #include "../vmisc/dialogs/vshortcutdialog.h" #include "../vmisc/theme/vtheme.h" #include "../vmisc/vabstractshortcutmanager.h" +#include "../vwidgets/vmousewheelwidgetadjustmentguard.h" #include "ui_puzzlepreferencesconfigurationpage.h" #include @@ -43,6 +44,16 @@ PuzzlePreferencesConfigurationPage::PuzzlePreferencesConfigurationPage(QWidget * { ui->setupUi(this); + // Prevent stealing focus when scrolling + VMouseWheelWidgetAdjustmentGuard::InstallEventFilter(ui->langCombo); + VMouseWheelWidgetAdjustmentGuard::InstallEventFilter(ui->comboBoxThemeMode); + VMouseWheelWidgetAdjustmentGuard::InstallEventFilter(ui->undoCount); + VMouseWheelWidgetAdjustmentGuard::InstallEventFilter(ui->spinBoxDuration); + VMouseWheelWidgetAdjustmentGuard::InstallEventFilter(ui->spinBoxUpdateInterval); + VMouseWheelWidgetAdjustmentGuard::InstallEventFilter(ui->doubleSpinBoxSensor); + VMouseWheelWidgetAdjustmentGuard::InstallEventFilter(ui->doubleSpinBoxWheel); + VMouseWheelWidgetAdjustmentGuard::InstallEventFilter(ui->doubleSpinBoxAcceleration); + InitLanguages(ui->langCombo); connect(ui->langCombo, QOverload::of(&QComboBox::currentIndexChanged), this, [this]() { m_langChanged = true; }); diff --git a/src/app/puzzle/vpmainwindow.cpp b/src/app/puzzle/vpmainwindow.cpp index 0275f3f53..7acf931d0 100644 --- a/src/app/puzzle/vpmainwindow.cpp +++ b/src/app/puzzle/vpmainwindow.cpp @@ -59,6 +59,7 @@ #include "../vmisc/theme/vtheme.h" #include "../vmisc/vsysexits.h" #include "../vwidgets/vmaingraphicsscene.h" +#include "../vwidgets/vmousewheelwidgetadjustmentguard.h" #include "dialogs/dialogpuzzlepreferences.h" #include "dialogs/dialogsavemanuallayout.h" #include "dialogs/vpdialogabout.h" @@ -333,6 +334,31 @@ VPMainWindow::VPMainWindow(const VPCommandLinePtr &cmd, QWidget *parent) { ui->setupUi(this); + // Prevent stealing focus when scrolling + VMouseWheelWidgetAdjustmentGuard::InstallEventFilter(ui->doubleSpinBoxCurrentPieceBoxPositionX); + VMouseWheelWidgetAdjustmentGuard::InstallEventFilter(ui->doubleSpinBoxCurrentPieceBoxPositionY); + VMouseWheelWidgetAdjustmentGuard::InstallEventFilter(ui->doubleSpinBoxCurrentPieceAngle); + VMouseWheelWidgetAdjustmentGuard::InstallEventFilter(ui->comboBoxLayoutUnit); + VMouseWheelWidgetAdjustmentGuard::InstallEventFilter(ui->comboBoxSheetTemplates); + VMouseWheelWidgetAdjustmentGuard::InstallEventFilter(ui->doubleSpinBoxSheetPaperWidth); + VMouseWheelWidgetAdjustmentGuard::InstallEventFilter(ui->doubleSpinBoxSheetPaperHeight); + VMouseWheelWidgetAdjustmentGuard::InstallEventFilter(ui->doubleSpinBoxSheetMarginTop); + VMouseWheelWidgetAdjustmentGuard::InstallEventFilter(ui->doubleSpinBoxSheetMarginLeft); + VMouseWheelWidgetAdjustmentGuard::InstallEventFilter(ui->doubleSpinBoxSheetMarginRight); + VMouseWheelWidgetAdjustmentGuard::InstallEventFilter(ui->doubleSpinBoxSheetMarginBottom); + VMouseWheelWidgetAdjustmentGuard::InstallEventFilter(ui->doubleSpinBoxSheetGridColWidth); + VMouseWheelWidgetAdjustmentGuard::InstallEventFilter(ui->doubleSpinBoxSheetGridRowHeight); + VMouseWheelWidgetAdjustmentGuard::InstallEventFilter(ui->comboBoxTileTemplates); + VMouseWheelWidgetAdjustmentGuard::InstallEventFilter(ui->doubleSpinBoxTilePaperWidth); + VMouseWheelWidgetAdjustmentGuard::InstallEventFilter(ui->doubleSpinBoxTilePaperHeight); + VMouseWheelWidgetAdjustmentGuard::InstallEventFilter(ui->doubleSpinBoxTileMarginTop); + VMouseWheelWidgetAdjustmentGuard::InstallEventFilter(ui->doubleSpinBoxTileMarginLeft); + VMouseWheelWidgetAdjustmentGuard::InstallEventFilter(ui->doubleSpinBoxTileMarginRight); + VMouseWheelWidgetAdjustmentGuard::InstallEventFilter(ui->doubleSpinBoxTileMarginBottom); + VMouseWheelWidgetAdjustmentGuard::InstallEventFilter(ui->doubleSpinBoxSheetPiecesGap); + VMouseWheelWidgetAdjustmentGuard::InstallEventFilter(ui->doubleSpinBoxHorizontalScale); + VMouseWheelWidgetAdjustmentGuard::InstallEventFilter(ui->doubleSpinBoxVerticalScale); + connect(m_layout.data(), &VPLayout::PieceSelectionChanged, this, &VPMainWindow::on_PieceSelectionChanged); connect(m_layout.data(), &VPLayout::LayoutChanged, this, [this]() { LayoutWasSaved(false); }); connect(m_layout.data(), &VPLayout::PieceTransformationChanged, this, diff --git a/src/app/tape/dialogs/configpages/tapepreferencesconfigurationpage.cpp b/src/app/tape/dialogs/configpages/tapepreferencesconfigurationpage.cpp index 4c8291017..0ce6dde7d 100644 --- a/src/app/tape/dialogs/configpages/tapepreferencesconfigurationpage.cpp +++ b/src/app/tape/dialogs/configpages/tapepreferencesconfigurationpage.cpp @@ -35,8 +35,10 @@ #include "../vmisc/dialogs/vshortcutdialog.h" #include "../vmisc/theme/vtheme.h" #include "../vmisc/vabstractshortcutmanager.h" +#include "../vwidgets/vmousewheelwidgetadjustmentguard.h" #include "ui_tapepreferencesconfigurationpage.h" +#include #include //--------------------------------------------------------------------------------------------------------------------- @@ -49,6 +51,11 @@ TapePreferencesConfigurationPage::TapePreferencesConfigurationPage(QWidget *pare ui->setupUi(this); RetranslateUi(); + // Prevent stealing focus when scrolling + VMouseWheelWidgetAdjustmentGuard::InstallEventFilter(ui->langCombo); + VMouseWheelWidgetAdjustmentGuard::InstallEventFilter(ui->comboBoxKnownMeasurements); + VMouseWheelWidgetAdjustmentGuard::InstallEventFilter(ui->comboBoxThemeMode); + InitLanguages(ui->langCombo); connect(ui->langCombo, QOverload::of(&QComboBox::currentIndexChanged), this, [this]() { m_langChanged = true; }); diff --git a/src/app/valentina/dialogs/configpages/preferencesconfigurationpage.cpp b/src/app/valentina/dialogs/configpages/preferencesconfigurationpage.cpp index 2ec566c95..df2541b05 100644 --- a/src/app/valentina/dialogs/configpages/preferencesconfigurationpage.cpp +++ b/src/app/valentina/dialogs/configpages/preferencesconfigurationpage.cpp @@ -35,6 +35,7 @@ #include "../vmisc/theme/vtheme.h" #include "../vmisc/vabstractshortcutmanager.h" #include "../vmisc/vvalentinasettings.h" +#include "../vwidgets/vmousewheelwidgetadjustmentguard.h" #include "ui_preferencesconfigurationpage.h" #include "vcommonsettings.h" @@ -52,6 +53,15 @@ PreferencesConfigurationPage::PreferencesConfigurationPage(QWidget *parent) ui->setupUi(this); RetranslateUi(); + // Prevent stealing focus when scrolling + VMouseWheelWidgetAdjustmentGuard::InstallEventFilter(ui->autoTime); + VMouseWheelWidgetAdjustmentGuard::InstallEventFilter(ui->langCombo); + VMouseWheelWidgetAdjustmentGuard::InstallEventFilter(ui->comboBoxPieceLbelLanguage); + VMouseWheelWidgetAdjustmentGuard::InstallEventFilter(ui->unitCombo); + VMouseWheelWidgetAdjustmentGuard::InstallEventFilter(ui->labelCombo); + VMouseWheelWidgetAdjustmentGuard::InstallEventFilter(ui->comboBoxThemeMode); + VMouseWheelWidgetAdjustmentGuard::InstallEventFilter(ui->comboBoxPointerMode); + ui->tabWidget->setCurrentIndex(0); // Tab General diff --git a/src/app/valentina/dialogs/configpages/preferencespatternpage.cpp b/src/app/valentina/dialogs/configpages/preferencespatternpage.cpp index 8b0fd0e54..a80a746fb 100644 --- a/src/app/valentina/dialogs/configpages/preferencespatternpage.cpp +++ b/src/app/valentina/dialogs/configpages/preferencespatternpage.cpp @@ -35,6 +35,7 @@ #include "../vmisc/vabstractvalapplication.h" #include "../vmisc/vvalentinasettings.h" #include "../vwidgets/vmaingraphicsview.h" +#include "../vwidgets/vmousewheelwidgetadjustmentguard.h" #include "svgfont/svgdef.h" #include "svgfont/vsvgfont.h" #include "svgfont/vsvgfontengine.h" @@ -74,6 +75,18 @@ PreferencesPatternPage::PreferencesPatternPage(QWidget *parent) ui->setupUi(this); RetranslateUi(); + // Prevent stealing focus when scrolling + VMouseWheelWidgetAdjustmentGuard::InstallEventFilter(ui->doubleSpinBoxCurveApproximation); + VMouseWheelWidgetAdjustmentGuard::InstallEventFilter(ui->doubleSpinBoxLineWidth); + VMouseWheelWidgetAdjustmentGuard::InstallEventFilter(ui->comboBoxLineWidthUnit); + VMouseWheelWidgetAdjustmentGuard::InstallEventFilter(ui->defaultSeamAllowance); + VMouseWheelWidgetAdjustmentGuard::InstallEventFilter(ui->comboBoxLabelFontSize); + VMouseWheelWidgetAdjustmentGuard::InstallEventFilter(ui->fontComboBoxLabelFont); + VMouseWheelWidgetAdjustmentGuard::InstallEventFilter(ui->comboBoxSingleLineFont); + VMouseWheelWidgetAdjustmentGuard::InstallEventFilter(ui->comboBoxDateFormats); + VMouseWheelWidgetAdjustmentGuard::InstallEventFilter(ui->comboBoxTimeFormats); + VMouseWheelWidgetAdjustmentGuard::InstallEventFilter(ui->spinBoxOpacity); + VValentinaSettings *settings = VAbstractValApplication::VApp()->ValentinaSettings(); ui->graphOutputCheck->setChecked(settings->GetGraphicalOutput()); diff --git a/src/app/valentina/dialogs/dialoglayoutsettings.cpp b/src/app/valentina/dialogs/dialoglayoutsettings.cpp index 1c935dfdc..c7750d059 100644 --- a/src/app/valentina/dialogs/dialoglayoutsettings.cpp +++ b/src/app/valentina/dialogs/dialoglayoutsettings.cpp @@ -30,6 +30,7 @@ #include "../vlayout/vlayoutgenerator.h" #include "../vmisc/vabstractvalapplication.h" #include "../vmisc/vvalentinasettings.h" +#include "../vwidgets/vmousewheelwidgetadjustmentguard.h" #include "ui_dialoglayoutsettings.h" #include @@ -54,6 +55,22 @@ DialogLayoutSettings::DialogLayoutSettings(VLayoutGenerator *generator, QWidget { ui->setupUi(this); + // Prevent stealing focus when scrolling + VMouseWheelWidgetAdjustmentGuard::InstallEventFilter(ui->comboBoxTemplates); + VMouseWheelWidgetAdjustmentGuard::InstallEventFilter(ui->doubleSpinBoxPaperWidth); + VMouseWheelWidgetAdjustmentGuard::InstallEventFilter(ui->doubleSpinBoxPaperHeight); + VMouseWheelWidgetAdjustmentGuard::InstallEventFilter(ui->comboBoxPaperSizeUnit); + VMouseWheelWidgetAdjustmentGuard::InstallEventFilter(ui->comboBoxPaperSizeUnit); + VMouseWheelWidgetAdjustmentGuard::InstallEventFilter(ui->doubleSpinBoxLeftField); + VMouseWheelWidgetAdjustmentGuard::InstallEventFilter(ui->doubleSpinBoxRightField); + VMouseWheelWidgetAdjustmentGuard::InstallEventFilter(ui->doubleSpinBoxTopField); + VMouseWheelWidgetAdjustmentGuard::InstallEventFilter(ui->doubleSpinBoxBottomField); + VMouseWheelWidgetAdjustmentGuard::InstallEventFilter(ui->doubleSpinBoxLayoutWidth); + VMouseWheelWidgetAdjustmentGuard::InstallEventFilter(ui->comboBoxLayoutUnit); + VMouseWheelWidgetAdjustmentGuard::InstallEventFilter(ui->spinBoxNestingTime); + VMouseWheelWidgetAdjustmentGuard::InstallEventFilter(ui->doubleSpinBoxEfficiency); + VMouseWheelWidgetAdjustmentGuard::InstallEventFilter(ui->spinBoxMultiplier); + VAbstractValApplication::VApp()->ValentinaSettings()->GetOsSeparator() ? setLocale(QLocale()) : setLocale(QLocale::c()); @@ -537,7 +554,8 @@ auto DialogLayoutSettings::PageToPixels(qreal value) const -> qreal auto DialogLayoutSettings::MakeGroupsHelp() -> QString { // that is REALLY dummy ... can't figure fast how to automate generation... :/ - return tr("\n\tThree groups: big, middle, small = 0;\n\tTwo groups: big, small = 1;\n\tDescending area = 2"); + return tr("\n\tThree groups: big, middle, small = 0;\n\tTwo groups: big, small = " + "1;\n\tDescending area = 2"); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/valentina/dialogs/vwidgetbackgroundimages.cpp b/src/app/valentina/dialogs/vwidgetbackgroundimages.cpp index 0fa76a88d..fa54ad82e 100644 --- a/src/app/valentina/dialogs/vwidgetbackgroundimages.cpp +++ b/src/app/valentina/dialogs/vwidgetbackgroundimages.cpp @@ -42,6 +42,7 @@ #include "../vtools/undocommands/image/rotatebackgroundimage.h" #include "../vtools/undocommands/image/scalebackgroundimage.h" #include "../vtools/undocommands/image/zvaluemovebackgroundimage.h" +#include "../vwidgets/vmousewheelwidgetadjustmentguard.h" #include "ui_vwidgetbackgroundimages.h" #include @@ -154,6 +155,15 @@ VWidgetBackgroundImages::VWidgetBackgroundImages(VAbstractPattern *doc, QWidget { ui->setupUi(this); + // Prevent stealing focus when scrolling + VMouseWheelWidgetAdjustmentGuard::InstallEventFilter(ui->doubleSpinBoxImageHorizontalTranslate); + VMouseWheelWidgetAdjustmentGuard::InstallEventFilter(ui->comboBoxTranslateUnit); + VMouseWheelWidgetAdjustmentGuard::InstallEventFilter(ui->doubleSpinBoxImageVerticalTranslate); + VMouseWheelWidgetAdjustmentGuard::InstallEventFilter(ui->doubleSpinBoxScaleWidth); + VMouseWheelWidgetAdjustmentGuard::InstallEventFilter(ui->comboBoxScaleUnit); + VMouseWheelWidgetAdjustmentGuard::InstallEventFilter(ui->doubleSpinBoxScaleHeight); + VMouseWheelWidgetAdjustmentGuard::InstallEventFilter(ui->doubleSpinBoxRotationAngle); + SCASSERT(doc != nullptr) UpdateImages(); diff --git a/src/libs/vlayout/dialogs/watermarkwindow.cpp b/src/libs/vlayout/dialogs/watermarkwindow.cpp index 035c31c24..b217b39d1 100644 --- a/src/libs/vlayout/dialogs/watermarkwindow.cpp +++ b/src/libs/vlayout/dialogs/watermarkwindow.cpp @@ -44,6 +44,7 @@ #include "../vmisc/def.h" #include "../vmisc/vabstractapplication.h" #include "../vpropertyexplorer/checkablemessagebox.h" +#include "../vwidgets/vmousewheelwidgetadjustmentguard.h" #if QT_VERSION < QT_VERSION_CHECK(6, 4, 0) #include "../vmisc/compatibility.h" @@ -58,6 +59,12 @@ WatermarkWindow::WatermarkWindow(const QString &patternPath, QWidget *parent) m_patternPath(patternPath) { ui->setupUi(this); + + // Prevent stealing focus when scrolling + VMouseWheelWidgetAdjustmentGuard::InstallEventFilter(ui->spinBoxOpacity); + VMouseWheelWidgetAdjustmentGuard::InstallEventFilter(ui->spinBoxTextRotation); + VMouseWheelWidgetAdjustmentGuard::InstallEventFilter(ui->spinBoxImageRotation); + m_okPathColor = ui->lineEditPath->palette().color(ui->lineEditPath->foregroundRole()); VAbstractApplication::VApp()->Settings()->GetOsSeparator() ? setLocale(QLocale()) : setLocale(QLocale::c()); diff --git a/src/libs/vtools/dialogs/tools/dialogsplinepath.cpp b/src/libs/vtools/dialogs/tools/dialogsplinepath.cpp index f81131098..a91d72692 100644 --- a/src/libs/vtools/dialogs/tools/dialogsplinepath.cpp +++ b/src/libs/vtools/dialogs/tools/dialogsplinepath.cpp @@ -59,6 +59,7 @@ #include "../vpatterndb/vtranslatevars.h" #include "../vwidgets/vabstractmainwindow.h" #include "../vwidgets/vmaingraphicsscene.h" +#include "../vwidgets/vmousewheelwidgetadjustmentguard.h" #include "ui_dialogsplinepath.h" #if QT_VERSION < QT_VERSION_CHECK(6, 4, 0) @@ -79,6 +80,13 @@ DialogSplinePath::DialogSplinePath(const VContainer *data, VAbstractPattern *doc { ui->setupUi(this); + // Prevent stealing focus when scrolling + VMouseWheelWidgetAdjustmentGuard::InstallEventFilter(ui->comboBoxNewPoint); + VMouseWheelWidgetAdjustmentGuard::InstallEventFilter(ui->comboBoxPoint); + VMouseWheelWidgetAdjustmentGuard::InstallEventFilter(ui->comboBoxPenStyle); + VMouseWheelWidgetAdjustmentGuard::InstallEventFilter(ui->comboBoxColor); + VMouseWheelWidgetAdjustmentGuard::InstallEventFilter(ui->doubleSpinBoxApproximationScale); + InitIcons(); formulaBaseHeightAngle1 = ui->plainTextEditAngle1F->height(); diff --git a/src/libs/vtools/dialogs/tools/piece/dialogseamallowance.cpp b/src/libs/vtools/dialogs/tools/piece/dialogseamallowance.cpp index 9794fa627..da98571b0 100644 --- a/src/libs/vtools/dialogs/tools/piece/dialogseamallowance.cpp +++ b/src/libs/vtools/dialogs/tools/piece/dialogseamallowance.cpp @@ -50,6 +50,7 @@ #include "../vpatterndb/vpiecenode.h" #include "../vpatterndb/vpiecepath.h" #include "../vwidgets/fancytabbar/fancytabbar.h" +#include "../vwidgets/vmousewheelwidgetadjustmentguard.h" #include "dialogpatternmaterials.h" #include "dialogpiecepath.h" #include "dialogplacelabel.h" @@ -203,6 +204,33 @@ DialogSeamAllowance::DialogSeamAllowance(const VContainer *data, VAbstractPatter InitIcons(); + // Prevent stealing focus when scrolling + VMouseWheelWidgetAdjustmentGuard::InstallEventFilter(uiTabGrainline->comboBoxGrainlineCenterPin); + VMouseWheelWidgetAdjustmentGuard::InstallEventFilter(uiTabGrainline->comboBoxGrainlineTopPin); + VMouseWheelWidgetAdjustmentGuard::InstallEventFilter(uiTabGrainline->comboBoxGrainlineBottomPin); + VMouseWheelWidgetAdjustmentGuard::InstallEventFilter(uiTabGrainline->comboBoxArrow); + VMouseWheelWidgetAdjustmentGuard::InstallEventFilter(uiTabLabels->comboBoxPieceLabelSize); + VMouseWheelWidgetAdjustmentGuard::InstallEventFilter(uiTabLabels->comboBoxDLCenterPin); + VMouseWheelWidgetAdjustmentGuard::InstallEventFilter(uiTabLabels->comboBoxDLTopLeftPin); + VMouseWheelWidgetAdjustmentGuard::InstallEventFilter(uiTabLabels->comboBoxDLBottomRightPin); + VMouseWheelWidgetAdjustmentGuard::InstallEventFilter(uiTabLabels->comboBoxPatternLabelSize); + VMouseWheelWidgetAdjustmentGuard::InstallEventFilter(uiTabLabels->comboBoxPLCenterPin); + VMouseWheelWidgetAdjustmentGuard::InstallEventFilter(uiTabLabels->comboBoxPLTopLeftPin); + VMouseWheelWidgetAdjustmentGuard::InstallEventFilter(uiTabLabels->comboBoxPLBottomRightPin); + VMouseWheelWidgetAdjustmentGuard::InstallEventFilter(uiTabLabels->dateEditCustomerBirthDate); + VMouseWheelWidgetAdjustmentGuard::InstallEventFilter(uiTabLabels->comboBoxDateFormat); + VMouseWheelWidgetAdjustmentGuard::InstallEventFilter(uiTabLabels->comboBoxTimeFormat); + VMouseWheelWidgetAdjustmentGuard::InstallEventFilter(uiTabLabels->spinBoxQuantity); + VMouseWheelWidgetAdjustmentGuard::InstallEventFilter(uiTabPassmarks->comboBoxPassmarks); + VMouseWheelWidgetAdjustmentGuard::InstallEventFilter(uiTabPaths->comboBoxMLStartPoint); + VMouseWheelWidgetAdjustmentGuard::InstallEventFilter(uiTabPaths->comboBoxMLEndPoint); + VMouseWheelWidgetAdjustmentGuard::InstallEventFilter(uiTabPaths->spinBoxPriority); + VMouseWheelWidgetAdjustmentGuard::InstallEventFilter(uiTabPaths->comboBoxNodes); + VMouseWheelWidgetAdjustmentGuard::InstallEventFilter(uiTabPaths->comboBoxAngle); + VMouseWheelWidgetAdjustmentGuard::InstallEventFilter(uiTabPaths->comboBoxStartPoint); + VMouseWheelWidgetAdjustmentGuard::InstallEventFilter(uiTabPaths->comboBoxEndPoint); + VMouseWheelWidgetAdjustmentGuard::InstallEventFilter(uiTabPaths->comboBoxIncludeType); + ChangeColor(uiTabPaths->labelEditName, OkColor(this)); flagMainPathIsValid = MainPathIsValid(); diff --git a/src/libs/vwidgets/vmousewheelwidgetadjustmentguard.cpp b/src/libs/vwidgets/vmousewheelwidgetadjustmentguard.cpp new file mode 100644 index 000000000..77da36491 --- /dev/null +++ b/src/libs/vwidgets/vmousewheelwidgetadjustmentguard.cpp @@ -0,0 +1,62 @@ +/************************************************************************ + ** + ** @file vmousewheelwidgetadjustmentguard.cpp + ** @author Roman Telezhynskyi + ** @date 31 1, 2024 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentina project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2024 Valentina project + ** All Rights Reserved. + ** + ** Valentina is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ +#include "vmousewheelwidgetadjustmentguard.h" + +#include +#include + +//--------------------------------------------------------------------------------------------------------------------- +VMouseWheelWidgetAdjustmentGuard::VMouseWheelWidgetAdjustmentGuard(QObject *parent) + : QObject{parent} +{ +} + +//--------------------------------------------------------------------------------------------------------------------- +void VMouseWheelWidgetAdjustmentGuard::InstallEventFilter(QWidget *w) +{ + if (w == nullptr) + { + return; + } + + w->setFocusPolicy(Qt::StrongFocus); + w->installEventFilter(new VMouseWheelWidgetAdjustmentGuard(w)); +} + +//--------------------------------------------------------------------------------------------------------------------- +auto VMouseWheelWidgetAdjustmentGuard::eventFilter(QObject *o, QEvent *e) -> bool +{ + const QWidget *widget = qobject_cast(o); + if (e->type() == QEvent::Wheel && (widget != nullptr) && !widget->hasFocus()) + { + e->ignore(); + return true; + } + + return QObject::eventFilter(o, e); +} diff --git a/src/libs/vwidgets/vmousewheelwidgetadjustmentguard.h b/src/libs/vwidgets/vmousewheelwidgetadjustmentguard.h new file mode 100644 index 000000000..3258c704e --- /dev/null +++ b/src/libs/vwidgets/vmousewheelwidgetadjustmentguard.h @@ -0,0 +1,56 @@ +/************************************************************************ + ** + ** @file vmousewheelwidgetadjustmentguard.h + ** @author Roman Telezhynskyi + ** @date 31 1, 2024 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentina project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2024 Valentina project + ** All Rights Reserved. + ** + ** Valentina is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ +#ifndef VMOUSEWHEELWIDGETADJUSTMENTGUARD_H +#define VMOUSEWHEELWIDGETADJUSTMENTGUARD_H + +#include "qtclasshelpermacros.h" +#include + +// Helps to prevent widget from stealing scroll event. +// Install event filter +// Example: +// VMouseWheelWidgetAdjustmentGuard::InstallEventFilter(ui->comboBox); + +class VMouseWheelWidgetAdjustmentGuard : public QObject +{ + Q_OBJECT // NOLINT + +public: + explicit VMouseWheelWidgetAdjustmentGuard(QObject *parent = nullptr); + ~VMouseWheelWidgetAdjustmentGuard() override = default; + + static void InstallEventFilter(QWidget *w); + +protected: + auto eventFilter(QObject *o, QEvent *e) -> bool override; + +private: + Q_DISABLE_COPY_MOVE(VMouseWheelWidgetAdjustmentGuard) // NOLINT +}; + +#endif // VMOUSEWHEELWIDGETADJUSTMENTGUARD_H diff --git a/src/libs/vwidgets/vwidgets.pri b/src/libs/vwidgets/vwidgets.pri index 72e462278..ca868fdb9 100644 --- a/src/libs/vwidgets/vwidgets.pri +++ b/src/libs/vwidgets/vwidgets.pri @@ -31,7 +31,8 @@ SOURCES += \ $$PWD/vhighlighter.cpp \ $$PWD/vpiecegrainline.cpp \ $$PWD/vtoolbuttonpopup.cpp \ - $$PWD/vaspectratiopixmaplabel.cpp + $$PWD/vaspectratiopixmaplabel.cpp \ + $$PWD/vmousewheelwidgetadjustmentguard.cpp *msvc*:SOURCES += $$PWD/stable.cpp @@ -67,5 +68,6 @@ HEADERS += \ $$PWD/vpiecegrainline.h \ $$PWD/vpiecegrainline_p.h \ $$PWD/vtoolbuttonpopup.h \ - $$PWD/vaspectratiopixmaplabel.h + $$PWD/vaspectratiopixmaplabel.h \ + $$PWD/vmousewheelwidgetadjustmentguard.h diff --git a/src/libs/vwidgets/vwidgets.qbs b/src/libs/vwidgets/vwidgets.qbs index 2ea3dd0c3..133b1fa71 100644 --- a/src/libs/vwidgets/vwidgets.qbs +++ b/src/libs/vwidgets/vwidgets.qbs @@ -21,6 +21,8 @@ VLib { "velidedlabel.cpp", "vmaingraphicsscene.cpp", "vmaingraphicsview.cpp", + "vmousewheelwidgetadjustmentguard.cpp", + "vmousewheelwidgetadjustmentguard.h", "vtoolbuttonpopup.cpp", "vtoolbuttonpopup.h", "vwidgetpopup.cpp",