Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions YACReader/configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ void Configuration::load(QSettings *settings)
settings->setValue(DOUBLE_PAGE, false);
if (!settings->contains(BACKGROUND_COLOR))
settings->setValue(BACKGROUND_COLOR, QColor(40, 40, 40));
if (!settings->contains(ALWAYS_ON_TOP))
settings->setValue(ALWAYS_ON_TOP, false);
if (!settings->contains(SHOW_TOOLBARS))
settings->setValue(SHOW_TOOLBARS, true);
if (!settings->contains(QUICK_NAVI_MODE))
Expand Down
2 changes: 0 additions & 2 deletions YACReader/configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,6 @@ class Configuration : public QObject

QColor getBackgroundColor() { return settings->value(BACKGROUND_COLOR).value<QColor>(); }
void setBackgroundColor(const QColor &color) { settings->value(BACKGROUND_COLOR, color); }
bool getAlwaysOnTop() { return settings->value(ALWAYS_ON_TOP).toBool(); }
void setAlwaysOnTop(bool b) { settings->setValue(ALWAYS_ON_TOP, b); }
bool getShowToolbars() { return settings->value(SHOW_TOOLBARS).toBool(); }
void setShowToolbars(bool b) { settings->setValue(SHOW_TOOLBARS, b); }
bool getShowInformation() { return settings->value(SHOW_INFO, false).toBool(); }
Expand Down
122 changes: 67 additions & 55 deletions YACReader/magnifying_glass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ void MagnifyingGlass::updateImage(int x, int y)
// image section augmented
int zoomWidth = static_cast<int>(width() * zoomLevel);
int zoomHeight = static_cast<int>(height() * zoomLevel);
auto p = (Viewer *)parent();
auto *const p = qobject_cast<const Viewer *>(parentWidget());
int currentPos = p->verticalScrollBar()->sliderPosition();
const QPixmap image = p->pixmap();
int iWidth = image.width();
Expand Down Expand Up @@ -170,101 +170,113 @@ void MagnifyingGlass::wheelEvent(QWheelEvent *event)
else
zoomOut();
break;
default:
break; // Never propagate a wheel event to the parent widget, even if we ignore it.
}
updateImage();
event->setAccepted(true);
}
void MagnifyingGlass::zoomIn()
{
if (zoomLevel > 0.2f)
if (zoomLevel > 0.2f) {
zoomLevel -= 0.025f;
updateImage();
}
}

void MagnifyingGlass::zoomOut()
{
if (zoomLevel < 0.9f)
if (zoomLevel < 0.9f) {
zoomLevel += 0.025f;
updateImage();
}
}

void MagnifyingGlass::sizeUp()
{
auto p = (Viewer *)parent();
if (width() < (p->width() * 0.90f))
resize(width() + 30, height() + 15);
auto w = width();
auto h = height();
if (growWidth(w) | growHeight(h)) // bitwise OR prevents short-circuiting
resizeAndUpdate(w, h);
}

void MagnifyingGlass::sizeDown()
{
if (width() > 175)
resize(width() - 30, height() - 15);
auto w = width();
auto h = height();
if (shrinkWidth(w) | shrinkHeight(h)) // bitwise OR prevents short-circuiting
resizeAndUpdate(w, h);
}

void MagnifyingGlass::heightUp()
{
auto p = (Viewer *)parent();
if (height() < (p->height() * 0.90f))
resize(width(), height() + 15);
auto h = height();
if (growHeight(h))
resizeAndUpdate(width(), h);
}

void MagnifyingGlass::heightDown()
{
if (height() > 80)
resize(width(), height() - 15);
auto h = height();
if (shrinkHeight(h))
resizeAndUpdate(width(), h);
}

void MagnifyingGlass::widthUp()
{
auto p = (Viewer *)parent();
if (width() < (p->width() * 0.90f))
resize(width() + 30, height());
auto w = width();
if (growWidth(w))
resizeAndUpdate(w, height());
}

void MagnifyingGlass::widthDown()
{
if (width() > 175)
resize(width() - 30, height());
auto w = width();
if (shrinkWidth(w))
resizeAndUpdate(w, height());
}

void MagnifyingGlass::keyPressEvent(QKeyEvent *event)
void MagnifyingGlass::resizeAndUpdate(int w, int h)
{
bool validKey = false;

int _key = event->key();
Qt::KeyboardModifiers modifiers = event->modifiers();

if (modifiers & Qt::ShiftModifier)
_key |= Qt::SHIFT;
if (modifiers & Qt::ControlModifier)
_key |= Qt::CTRL;
if (modifiers & Qt::MetaModifier)
_key |= Qt::META;
if (modifiers & Qt::AltModifier)
_key |= Qt::ALT;

QKeySequence key(_key);
resize(w, h);
updateImage();
}

if (key == ShortcutsManager::getShortcutsManager().getShortcut(SIZE_UP_MGLASS_ACTION_Y)) {
sizeUp();
validKey = true;
}
static constexpr auto maxRelativeDimension = 0.9;
static constexpr auto widthStep = 30;
static constexpr auto heightStep = 15;

else if (key == ShortcutsManager::getShortcutsManager().getShortcut(SIZE_DOWN_MGLASS_ACTION_Y)) {
sizeDown();
validKey = true;
}
bool MagnifyingGlass::growWidth(int &w) const
{
const auto maxWidth = parentWidget()->width() * maxRelativeDimension;
if (w >= maxWidth)
return false;
w += widthStep;
return true;
}

else if (key == ShortcutsManager::getShortcutsManager().getShortcut(ZOOM_IN_MGLASS_ACTION_Y)) {
zoomIn();
validKey = true;
}
bool MagnifyingGlass::shrinkWidth(int &w) const
{
constexpr auto minWidth = 175;
if (w <= minWidth)
return false;
w -= widthStep;
return true;
}

else if (key == ShortcutsManager::getShortcutsManager().getShortcut(ZOOM_OUT_MGLASS_ACTION_Y)) {
zoomOut();
validKey = true;
}
bool MagnifyingGlass::growHeight(int &h) const
{
const auto maxHeight = parentWidget()->height() * maxRelativeDimension;
if (h >= maxHeight)
return false;
h += heightStep;
return true;
}

if (validKey) {
updateImage();
event->setAccepted(true);
}
bool MagnifyingGlass::shrinkHeight(int &h) const
{
constexpr auto minHeight = 80;
if (h <= minHeight)
return false;
h -= heightStep;
return true;
}
10 changes: 9 additions & 1 deletion YACReader/magnifying_glass.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,15 @@ class MagnifyingGlass : public QLabel
private:
float zoomLevel;
void setup(const QSize &size);
void keyPressEvent(QKeyEvent *event) override;
void resizeAndUpdate(int w, int h);

// The following 4 functions increase/decrease their argument and return true,
// unless the maximum dimension value has been reached, in which case they
// do not modify the argument and return false.
bool growWidth(int &w) const;
bool shrinkWidth(int &w) const;
bool growHeight(int &h) const;
bool shrinkHeight(int &h) const;

public:
MagnifyingGlass(int width, int height, QWidget *parent);
Expand Down
Loading