Skip to content

Commit

Permalink
Mouse Wheel modifier keys are adjustable via Settings dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
EtlamGit committed Dec 25, 2019
1 parent 9c58cdb commit 7087df2
Show file tree
Hide file tree
Showing 4 changed files with 193 additions and 11 deletions.
16 changes: 10 additions & 6 deletions mapview.cpp
Expand Up @@ -160,14 +160,15 @@ void MapView::adjustZoom(double steps, bool allowZoomOut)
int ppc = ceil(16*zoom);
int cx = (imageChunks.width() +ppc-1) / ppc;
int cz = (imageChunks.height()+ppc-1) / ppc;
chunks = 1.2 * (cx * cz);
if (chunks <= maxchunks)
restrictZoom = false; // everything matches
chunks = cx * cz;
if ((1.2 * chunks) <= maxchunks)
restrictZoom = false; // everything matches with a low margin of 20%
else
zoomIndex++; // restrict zoom
} while (restrictZoom);

cache.setCacheMaxSize(chunks);
// we try to set higher margin than above (100%)!
cache.setCacheMaxSize(2.0 * chunks);
}

static int lastMouseX = -1, lastMouseY = -1;
Expand Down Expand Up @@ -234,10 +235,13 @@ void MapView::mouseDoubleClickEvent(QMouseEvent *event) {
}

void MapView::wheelEvent(QWheelEvent *event) {
if ((event->modifiers() & Qt::ShiftModifier) == Qt::ShiftModifier) {
Qt::KeyboardModifier modifier4DepthSlider = Qt::KeyboardModifier(QSettings().value("modifier4DepthSlider", Qt::ShiftModifier).toUInt());
Qt::KeyboardModifier modifier4ZoomOut = Qt::KeyboardModifier(QSettings().value("modifier4ZoomOut", Qt::ControlModifier).toUInt());

if ((event->modifiers() & modifier4DepthSlider) == modifier4DepthSlider) {
// change depth
emit demandDepthChange(event->delta() / 120);
} if ((event->modifiers() & Qt::ControlModifier) == Qt::ControlModifier) {
} else if ((event->modifiers() & modifier4ZoomOut) == modifier4ZoomOut) {
// allow change zoom also to zoom OUT
adjustZoom( event->delta() / 120.0, true );
redraw();
Expand Down
90 changes: 88 additions & 2 deletions settings.cpp
Expand Up @@ -30,6 +30,20 @@ Settings::Settings(QWidget *parent) : QDialog(parent) {
connect(m_ui.checkBox_AutoUpdate, SIGNAL(toggled(bool)),
this, SLOT(toggleAutoUpdate(bool)));

connect(m_ui.radioButton_depth_shift, &QRadioButton::toggled,
this, &Settings::toggleModifier4DepthSlider);
connect(m_ui.radioButton_depth_ctrl, &QRadioButton::toggled,
this, &Settings::toggleModifier4DepthSlider);
connect(m_ui.radioButton_depth_alt, &QRadioButton::toggled,
this, &Settings::toggleModifier4DepthSlider);

connect(m_ui.radioButton_zoom_shift, &QRadioButton::toggled,
this, &Settings::toggleModifier4ZoomOut);
connect(m_ui.radioButton_zoom_ctrl, &QRadioButton::toggled,
this, &Settings::toggleModifier4ZoomOut);
connect(m_ui.radioButton_zoom_alt, &QRadioButton::toggled,
this, &Settings::toggleModifier4ZoomOut);

// Load the settings:
QSettings info;
auto useDefault = info.value("usedefault", true).toBool();
Expand All @@ -39,15 +53,41 @@ Settings::Settings(QWidget *parent) : QDialog(parent) {
else {
mcpath = info.value("mcdir", "").toString();
}
autoUpdate = info.value("autoupdate", true).toBool();
autoUpdate = info.value("autoupdate", true).toBool();
verticalDepth = info.value("verticaldepth", true).toBool();
modifier4DepthSlider = Qt::KeyboardModifier(info.value("modifier4DepthSlider", 0x02000000).toUInt());
modifier4ZoomOut = Qt::KeyboardModifier(info.value("modifier4ZoomOut", 0x04000000).toUInt());

// Set the UI to the current settings' values:
m_ui.checkBox_AutoUpdate->setChecked(autoUpdate);
m_ui.lineEdit_Location->setText(mcpath);
m_ui.lineEdit_Location->setDisabled(useDefault);
m_ui.checkBox_DefaultLocation->setChecked(useDefault);
m_ui.checkBox_VerticalDepth->setChecked(verticalDepth);
m_ui.checkBox_AutoUpdate->setChecked(autoUpdate);
switch (modifier4DepthSlider) {
case Qt::ControlModifier:
m_ui.radioButton_depth_ctrl->setChecked(true);
break;
case Qt::AltModifier:
m_ui.radioButton_depth_alt->setChecked(true);
break;
default:
m_ui.radioButton_depth_shift->setChecked(true);
break;
}
switch (modifier4ZoomOut) {
case Qt::ControlModifier:
m_ui.radioButton_zoom_ctrl->setChecked(true);
break;
case Qt::AltModifier:
m_ui.radioButton_zoom_alt->setChecked(true);
break;
default:
m_ui.radioButton_zoom_shift->setChecked(true);
break;
}
this->toggleModifier4DepthSlider();
this->toggleModifier4ZoomOut();
}

QString Settings::getDefaultLocation()
Expand Down Expand Up @@ -104,3 +144,49 @@ void Settings::toggleVerticalDepth(bool value) {
info.setValue("verticaldepth", value);
emit settingsUpdated();
}

void Settings::toggleModifier4DepthSlider() {
if (m_ui.radioButton_depth_shift->isChecked()) {
modifier4DepthSlider = Qt::ShiftModifier;
m_ui.radioButton_zoom_shift->setEnabled(false);
m_ui.radioButton_zoom_ctrl ->setEnabled(true);
m_ui.radioButton_zoom_alt ->setEnabled(true);
}
if (m_ui.radioButton_depth_ctrl->isChecked()) {
modifier4DepthSlider = Qt::ControlModifier;
m_ui.radioButton_zoom_shift->setEnabled(true);
m_ui.radioButton_zoom_ctrl ->setEnabled(false);
m_ui.radioButton_zoom_alt ->setEnabled(true);
}
if (m_ui.radioButton_depth_alt->isChecked()) {
modifier4DepthSlider = Qt::AltModifier;
m_ui.radioButton_zoom_shift->setEnabled(true);
m_ui.radioButton_zoom_ctrl ->setEnabled(true);
m_ui.radioButton_zoom_alt ->setEnabled(false);
}
QSettings info;
info.setValue("modifier4DepthSlider", modifier4DepthSlider);
}

void Settings::toggleModifier4ZoomOut() {
if (m_ui.radioButton_zoom_shift->isChecked()) {
modifier4ZoomOut = Qt::ShiftModifier;
m_ui.radioButton_depth_shift->setEnabled(false);
m_ui.radioButton_depth_ctrl ->setEnabled(true);
m_ui.radioButton_depth_alt ->setEnabled(true);
}
if (m_ui.radioButton_zoom_ctrl->isChecked()) {
modifier4ZoomOut = Qt::ControlModifier;
m_ui.radioButton_depth_shift->setEnabled(true);
m_ui.radioButton_depth_ctrl ->setEnabled(false);
m_ui.radioButton_depth_alt ->setEnabled(true);
}
if (m_ui.radioButton_zoom_alt->isChecked()) {
modifier4ZoomOut = Qt::AltModifier;
m_ui.radioButton_depth_shift->setEnabled(true);
m_ui.radioButton_depth_ctrl ->setEnabled(true);
m_ui.radioButton_depth_alt ->setEnabled(false);
}
QSettings info;
info.setValue("modifier4ZoomOut", modifier4ZoomOut);
}
8 changes: 6 additions & 2 deletions settings.h
Expand Up @@ -11,9 +11,11 @@ class Settings : public QDialog {
public:
explicit Settings(QWidget *parent = 0);

bool autoUpdate;
bool verticalDepth;
QString mcpath;
bool verticalDepth;
bool autoUpdate;
Qt::KeyboardModifier modifier4DepthSlider;
Qt::KeyboardModifier modifier4ZoomOut;

/** Returns the default path to be used for Minecraft location. */
static QString getDefaultLocation();
Expand All @@ -28,6 +30,8 @@ class Settings : public QDialog {
void toggleDefaultLocation(bool on);
void pathChanged(const QString &path);
void toggleVerticalDepth(bool on);
void toggleModifier4DepthSlider();
void toggleModifier4ZoomOut();

private:
Ui::Settings m_ui;
Expand Down
90 changes: 89 additions & 1 deletion settings.ui
Expand Up @@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>400</width>
<height>290</height>
<height>451</height>
</rect>
</property>
<property name="windowTitle">
Expand Down Expand Up @@ -85,6 +85,94 @@
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Mouse Wheel</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QGroupBox" name="groupBox_2">
<property name="title">
<string>Depth Slider</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_5">
<item>
<widget class="QRadioButton" name="radioButton_depth_shift">
<property name="text">
<string>Shift</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="radioButton_depth_ctrl">
<property name="text">
<string>Ctrl</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="radioButton_depth_alt">
<property name="text">
<string>Alt</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_3">
<property name="title">
<string>Zoom Out</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_6">
<item>
<widget class="QRadioButton" name="radioButton_zoom_shift">
<property name="text">
<string>Shift</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="radioButton_zoom_ctrl">
<property name="text">
<string>Ctrl</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="radioButton_zoom_alt">
<property name="text">
<string>Alt</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Without any modifier key, turning the mouse wheel controls zoom IN.</string>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
Expand Down

0 comments on commit 7087df2

Please sign in to comment.