Commit 5993b872 authored by Rafał Lalik's avatar Rafał Lalik Committed by Albert Astals Cid
Browse files

Adds scaling slider to the actions bar.

The scaling slider allows to scale between 'original size' and
'fit to window'. 'Original size' corresponds to previous 'Scale'
 action off. With 'Scale' enabled, additional slider widget (must
be add to visible widgets from ToolBar settings) the slider allows
to adjust scale size in 100 steps.
parent 8750c1bb
......@@ -132,6 +132,7 @@ set(krdc_SRCS
remotedesktopsmodel.cpp
systemtrayicon.cpp
tabbedviewwidget.cpp
factorwidget.cpp
mainwindow.cpp
main.cpp
)
......
/****************************************************************************
**
** Copyright (C) 2007 - 2010 Urs Wolfer <uwolfer @ kde.org>
** Copyright (C) 2021 Rafał Lalik <rafallalik @ gmail.com>
**
** This file is part of KDE.
**
......@@ -127,6 +128,16 @@ void HostPreferences::setWindowedScale(bool scale)
m_configGroup.writeEntry("windowedScale", scale);
}
int HostPreferences::scaleFactor()
{
return m_configGroup.readEntry("scaleFactor", 100);
}
void HostPreferences::setScaleFactor(int factor)
{
m_configGroup.writeEntry("scaleFactor", factor);
}
bool HostPreferences::grabAllKeys()
{
return m_configGroup.readEntry("grabAllKeys", false);
......
/****************************************************************************
**
** Copyright (C) 2007 Urs Wolfer <uwolfer @ kde.org>
** Copyright (C) 2021 Rafał Lalik <rafallalik @ gmail.com>
**
** This file is part of KDE.
**
......@@ -51,6 +52,10 @@ public:
bool windowedScale();
void setWindowedScale(bool scale);
/** Whether scaling is enabled when session is full screen. Note: only windowedScale seems to be used. */
int scaleFactor();
void setScaleFactor(int factor);
bool grabAllKeys();
void setGrabAllKeys(bool grab);
......
......@@ -2,6 +2,7 @@
**
** Copyright (C) 2002-2003 Tim Jansen <tim@tjansen.de>
** Copyright (C) 2007-2008 Urs Wolfer <uwolfer @ kde.org>
** Copyright (C) 2021 Rafał Lalik <rafallalik @ gmail.com>
**
** This file is part of KDE.
**
......@@ -38,6 +39,7 @@ RemoteView::RemoteView(QWidget *parent)
m_grabAllKeys(false),
m_scale(false),
m_keyboardIsGrabbed(false),
m_factor(0.),
#ifndef QTONLY
m_wallet(nullptr),
#endif
......@@ -186,6 +188,11 @@ void RemoteView::enableScaling(bool scale)
m_scale = scale;
}
void RemoteView::setScaleFactor(float factor)
{
m_factor = factor;
}
void RemoteView::switchFullscreen(bool)
{
}
......
......@@ -2,6 +2,7 @@
**
** Copyright (C) 2002-2003 Tim Jansen <tim@tjansen.de>
** Copyright (C) 2007-2008 Urs Wolfer <uwolfer @ kde.org>
** Copyright (C) 2021 Rafał Lalik <rafallalik @ gmail.com>
**
** This file is part of KDE.
**
......@@ -284,6 +285,16 @@ public Q_SLOTS:
*/
virtual void enableScaling(bool scale);
/**
* Sets scaling factor for the view. If remote view has width R and
* the window has width W, then scaling factor (float, range 0-1) set the
* remote view width A to be: A = (R-W)*factor + W. For factor = 0, A=W,
* so no scalling, for factor=1, A=R.
*
* @param factor scaling factor in the range 0-1
*/
virtual void setScaleFactor(float factor);
/**
* Enables/disables the view-only mode.
* Ignored if @ref supportsScaling() is false.
......@@ -319,6 +330,9 @@ public Q_SLOTS:
/**
* Called when the visible place changed so remote
* view can resize itself.
*
* @param w width of the remote view
* @param h height of the remote view
*/
virtual void scaleResize(int w, int h);
......@@ -406,6 +420,7 @@ protected:
bool m_scale;
bool m_keyboardIsGrabbed;
QUrl m_url;
qreal m_factor;
#ifndef QTONLY
QString readWalletPassword(bool fromUserNameOnly = false);
......
/****************************************************************************
**
** Copyright (C) 2021 Rafał Lalik <rafallalik @ gmail.com>
**
** This file is part of KDE.
**
** This program 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 2 of the License, or
** (at your option) any later version.
**
** This program 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 this program; see the file COPYING. If not, write to
** the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
** Boston, MA 02110-1301, USA.
**
****************************************************************************/
#include "factorwidget.h"
#include "mainwindow.h"
#include <QSlider>
#include <QToolBar>
#include <cstdio>
FactorWidget::FactorWidget(QWidget *parent) : QWidgetAction(parent)
{
}
FactorWidget::FactorWidget(const QString& text, MainWindow * receiver, QObject* parent)
: QWidgetAction(parent)
, m_receiver(receiver)
{
setText(text);
}
FactorWidget::~FactorWidget()
{
}
/**
* Each time action is add, the new QSlider widget is created and retun. As
* the toolbar takes ownership of the widget, here we must take care of
* conecting signals and slots to the MainWindow methods.
*
* The widget has by default 100 steps, and width of 100.
*/
QWidget * FactorWidget::createWidget(QWidget * parent)
{
QToolBar *_parent = qobject_cast<QToolBar *>(parent);
if (!_parent) {
return QWidgetAction::createWidget(parent);
}
QSlider * s = new QSlider(Qt::Horizontal, _parent);
s->setRange(0, 100);
s->setMaximumWidth(100);
connect(s, &QSlider::valueChanged, m_receiver, &MainWindow::setFactor);
connect(m_receiver, &MainWindow::factorUpdated, s, &QSlider::setValue);
connect(m_receiver, &MainWindow::scaleUpdated, s, &QSlider::setEnabled);
return s;
}
void FactorWidget::deleteWidget(QWidget* widget)
{
disconnect(widget);
QWidgetAction::deleteWidget(widget);
}
/****************************************************************************
**
** Copyright (C) 2021 Rafał Lalik <rafallalik @ gmail.com>
**
** This file is part of KDE.
**
** This program 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 2 of the License, or
** (at your option) any later version.
**
** This program 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 this program; see the file COPYING. If not, write to
** the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
** Boston, MA 02110-1301, USA.
**
****************************************************************************/
#ifndef FACTORWIDGET_H
#define FACTORWIDGET_H
#ifndef QTONLY
#include "krdccore_export.h"
#else
#define KRDCCORE_EXPORT
#endif
#include <QWidgetAction>
class MainWindow;
/**
* Widget Action to display slider in the action toolbar. Each time action is
* add, the new QSlider widget is created via @ref createWidget() method.
*/
class KRDCCORE_EXPORT FactorWidget : public QWidgetAction
{
Q_OBJECT
public:
FactorWidget(QWidget *parent = nullptr);
FactorWidget(const QString &text, MainWindow * receiver, QObject *parent = nullptr);
~FactorWidget();
protected:
virtual QWidget * createWidget(QWidget * parent) override;
virtual void deleteWidget(QWidget * widget) override;
MainWindow * m_receiver;
};
#endif
......@@ -2,6 +2,7 @@
**
** Copyright (C) 2007 - 2013 Urs Wolfer <uwolfer @ kde.org>
** Copyright (C) 2009 - 2010 Tony Murray <murraytony @ gmail.com>
** Copyright (C) 2021 Rafał Lalik <rafallalik @ gmail.com>
**
** This file is part of KDE.
**
......@@ -34,6 +35,7 @@
#include "systemtrayicon.h"
#include "tabbedviewwidget.h"
#include "hostpreferences.h"
#include "factorwidget.h"
#include <KActionCollection>
#include <KActionMenu>
......@@ -45,7 +47,7 @@
#include <KPluginMetaData>
#include <KToggleAction>
#include <KToggleFullScreenAction>
#include <QDebug>
#include <KToolBar>
#include <QClipboard>
#include <QDockWidget>
......@@ -189,6 +191,10 @@ void MainWindow::setupActions()
scaleAction->setIconText(i18n("Scale"));
connect(scaleAction, SIGNAL(triggered(bool)), SLOT(scale(bool)));
FactorWidget * m_scaleSlider = new FactorWidget(i18n("Scaling Factor"), this, actionCollection());
QAction * scaleFactorAction = actionCollection()->addAction(QStringLiteral("scale_factor"), m_scaleSlider);
scaleFactorAction->setIcon(QIcon::fromTheme(QStringLiteral("configure")));
KStandardAction::quit(this, SLOT(quit()), actionCollection());
KStandardAction::preferences(this, SLOT(preferences()), actionCollection());
QAction *configNotifyAction = KStandardAction::configureNotifications(this, SLOT(configureNotifications()), actionCollection());
......@@ -298,7 +304,11 @@ void MainWindow::newConnection(const QUrl &newUrl, bool switchFullscreenWhenConn
view->showLocalCursor(prefs->showLocalCursor() ? RemoteView::CursorOn : RemoteView::CursorOff);
view->setViewOnly(prefs->viewOnly());
if (! switchFullscreenWhenConnected) view->enableScaling(prefs->windowedScale());
bool scale_state = false;
if (switchFullscreenWhenConnected) scale_state = prefs->fullscreenScale();
else scale_state = prefs->windowedScale();
view->enableScaling(scale_state);
connect(view, SIGNAL(framebufferSizeChanged(int,int)), this, SLOT(resizeTabWidget(int,int)));
connect(view, SIGNAL(statusChanged(RemoteView::RemoteStatus)), this, SLOT(statusChanged(RemoteView::RemoteStatus)));
......@@ -317,6 +327,10 @@ void MainWindow::newConnection(const QUrl &newUrl, bool switchFullscreenWhenConn
tabChanged(newIndex); // force to update m_currentRemoteView (tabChanged is not emitted when start page has been disabled)
view->start();
setFactor(view->hostPreferences()->scaleFactor());
emit factorUpdated(view->hostPreferences()->scaleFactor());
emit scaleUpdated(scale_state);
}
void MainWindow::openFromRemoteDesktopsModel(const QModelIndex &index)
......@@ -456,6 +470,9 @@ void MainWindow::switchFullscreen()
{
qCDebug(KRDC);
RemoteView* view = currentRemoteView();
bool scale_state = false;
if (m_fullscreenWindow) {
// Leaving full screen mode
m_fullscreenWindow->setWindowState(Qt::WindowNoState);
......@@ -482,6 +499,8 @@ void MainWindow::switchFullscreen()
actionCollection()->action(QStringLiteral("switch_fullscreen"))->setIcon(QIcon::fromTheme(QStringLiteral("view-fullscreen")));
actionCollection()->action(QStringLiteral("switch_fullscreen"))->setText(i18n("Switch to Full Screen Mode"));
actionCollection()->action(QStringLiteral("switch_fullscreen"))->setIconText(i18n("Full Screen"));
if (view)
scale_state = view->hostPreferences()->windowedScale();
m_fullscreenWindow->deleteLater();
m_fullscreenWindow = nullptr;
......@@ -520,10 +539,18 @@ void MainWindow::switchFullscreen()
actionCollection()->action(QStringLiteral("switch_fullscreen"))->setText(i18n("Switch to Window Mode"));
actionCollection()->action(QStringLiteral("switch_fullscreen"))->setIconText(i18n("Window Mode"));
showRemoteViewToolbar();
if (view)
scale_state = view->hostPreferences()->fullscreenScale();
}
if (m_tabWidget->currentWidget() == m_newConnectionWidget && m_addressInput) {
m_addressInput->setFocus();
}
if (view) {
emit factorUpdated(view->hostPreferences()->scaleFactor());
emit scaleUpdated(scale_state);
}
actionCollection()->action(QStringLiteral("scale"))->setChecked(scale_state);
}
QScrollArea *MainWindow::createScrollArea(QWidget *parent, RemoteView *remoteView)
......@@ -755,6 +782,13 @@ void MainWindow::grabAllKeys(bool grabAllKeys)
saveHostPrefs(view);
}
void setActionStatus(QAction* action, bool enabled, bool visible, bool checked)
{
action->setEnabled(enabled);
action->setVisible(visible);
action->setChecked(checked);
}
void MainWindow::scale(bool scale)
{
qCDebug(KRDC);
......@@ -767,6 +801,23 @@ void MainWindow::scale(bool scale)
view->hostPreferences()->setWindowedScale(scale);
saveHostPrefs(view);
emit scaleUpdated(scale);
}
void MainWindow::setFactor(int scale)
{
float s = float(scale)/100.;
RemoteView* view = currentRemoteView();
if (view) {
view->setScaleFactor(s);
view->enableScaling(view->scaling());
view->hostPreferences()->setScaleFactor(scale);
saveHostPrefs(view);
}
}
void MainWindow::showRemoteViewToolbar()
......@@ -803,6 +854,7 @@ void MainWindow::showRemoteViewToolbar()
buttonBox->addAction(actionCollection()->action(QStringLiteral("show_local_cursor")));
buttonBox->addAction(actionCollection()->action(QStringLiteral("grab_all_keys")));
buttonBox->addAction(actionCollection()->action(QStringLiteral("scale")));
buttonBox->addAction(actionCollection()->action(QStringLiteral("scale_factor")));
buttonBox->addAction(actionCollection()->action(QStringLiteral("disconnect")));
buttonBox->addAction(actionCollection()->action(QStringLiteral("file_quit")));
......@@ -817,13 +869,6 @@ void MainWindow::showRemoteViewToolbar()
}
}
void setActionStatus(QAction* action, bool enabled, bool visible, bool checked)
{
action->setEnabled(enabled);
action->setVisible(visible);
action->setChecked(checked);
}
void MainWindow::updateActionStatus()
{
qCDebug(KRDC) << m_tabWidget->currentIndex();
......@@ -853,6 +898,9 @@ void MainWindow::updateActionStatus()
view ? view->supportsScaling() : false,
view ? view->scaling() : false);
actionCollection()->action(QStringLiteral("scale_factor"))->setEnabled(enabled);
actionCollection()->action(QStringLiteral("scale_factor"))->setVisible(view ? view->supportsScaling() : false);
setActionStatus(actionCollection()->action(QStringLiteral("grab_all_keys")),
enabled,
enabled,
......
......@@ -2,6 +2,7 @@
**
** Copyright (C) 2007 - 2013 Urs Wolfer <uwolfer @ kde.org>
** Copyright (C) 2009 - 2010 Tony Murray <murraytony @ gmail.com>
** Copyright (C) 2021 Rafał Lalik <rafallalik @ gmail.com>
**
** This file is part of KDE.
**
......@@ -65,6 +66,7 @@ public:
public Q_SLOTS:
void newConnection(const QUrl &newUrl = QUrl(), bool switchFullscreenWhenConnected = false, const QString &tabName = QString());
void setFactor(int scale);
protected:
void closeEvent(QCloseEvent *event) override;
......@@ -133,6 +135,10 @@ private:
QTableView *m_newConnectionTableView;
RemoteDesktopsModel *m_remoteDesktopsModel;
QWidget *m_newConnectionWidget;
Q_SIGNALS:
void scaleUpdated(bool scale); // scale state has changed
void factorUpdated(int factor); // factor havlue has changed
};
#include <QApplication>
......
/****************************************************************************
**
** Copyright (C) 2007 - 2013 Urs Wolfer <uwolfer @ kde.org>
** Copyright (C) 2021 Rafał Lalik <rafallalik @ gmail.com>
**
** This file is part of KDE.
**
......@@ -137,8 +138,11 @@ void VncView::scaleResize(int w, int h)
qCDebug(KRDC) << w << h;
if (m_scale) {
const QSize frameSize = m_frame.size() / m_frame.devicePixelRatio();
m_verticalFactor = (qreal) h / frameSize.height();
m_horizontalFactor = (qreal) w / frameSize.width();
const qreal _newW = (frameSize.width() - w) * m_factor + w;
const qreal _newH = (frameSize.height() - h) * m_factor + h;
m_verticalFactor = _newH / frameSize.height();
m_horizontalFactor = _newW / frameSize.width();
#ifndef QTONLY
if (Settings::keepAspectRatio()) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment