Commit 631983a0 authored by Aurélien Gâteau's avatar Aurélien Gâteau
Browse files

Refactor: ScrollTool is now handling the mouse wheel behavior.

svn path=/trunk/KDE/kdegraphics/gwenview/; revision=778296
parent ee85ebf5
......@@ -29,6 +29,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include "ui_configdialog.h"
#include <lib/gwenviewconfig.h>
#include <lib/invisiblebuttongroup.h>
#include <lib/scrolltool.h>
namespace Gwenview {
......@@ -54,8 +55,8 @@ ConfigDialog::ConfigDialog(QWidget* parent)
d->mWheelBehaviorGroup = new InvisibleButtonGroup(widget);
d->mWheelBehaviorGroup->setObjectName("kcfg_MouseWheelBehavior");
d->mWheelBehaviorGroup->addButton(d->mouseWheelScrollRadioButton, int(ImageView::MouseWheelScroll));
d->mWheelBehaviorGroup->addButton(d->mouseWheelBrowseRadioButton, int(ImageView::MouseWheelBrowse));
d->mWheelBehaviorGroup->addButton(d->mouseWheelScrollRadioButton, int(ScrollTool::MouseWheelScroll));
d->mWheelBehaviorGroup->addButton(d->mouseWheelBrowseRadioButton, int(ScrollTool::MouseWheelBrowse));
addPage(widget, "");
setHelp(QString(), "gwenview");
......
......@@ -179,9 +179,9 @@ void DocumentView::createPartForUrl(const KUrl& url) {
if (ivPart) {
connect(ivPart, SIGNAL(resizeRequested(const QSize&)),
d->mView, SIGNAL(resizeRequested(const QSize&)) );
connect(ivPart->imageView(), SIGNAL(previousImageRequested()),
connect(ivPart, SIGNAL(previousImageRequested()),
d->mView, SIGNAL(previousImageRequested()) );
connect(ivPart->imageView(), SIGNAL(nextImageRequested()),
connect(ivPart, SIGNAL(nextImageRequested()),
d->mView, SIGNAL(nextImageRequested()) );
}
......
......@@ -3,6 +3,7 @@
<kcfg>
<kcfgfile name="gwenviewrc"/>
<include>lib/imageview.h</include>
<include>lib/scrolltool.h</include>
<include>lib/print/printoptionspage.h</include>
<group name="SideBar">
<entry name="PreferredMetaInfoKeyList" type="StringList">
......@@ -35,11 +36,11 @@
</entry>
<entry name="MouseWheelBehavior" type="Enum">
<choices name="Gwenview::ImageView::MouseWheelBehavior">
<choice name="ImageView::MouseWheelScroll"/>
<choice name="ImageView::MouseWheelBrowse"/>
<choices name="Gwenview::ScrollTool::MouseWheelBehavior">
<choice name="ScrollTool::MouseWheelScroll"/>
<choice name="ScrollTool::MouseWheelBrowse"/>
</choices>
<default>ImageView::MouseWheelScroll</default>
<default>ScrollTool::MouseWheelScroll</default>
</entry>
</group>
......
......@@ -44,7 +44,6 @@ struct ImageViewPrivate {
QWidget* mViewport;
ImageView::AlphaBackgroundMode mAlphaBackgroundMode;
QColor mAlphaBackgroundColor;
ImageView::MouseWheelBehavior mMouseWheelBehavior;
const QImage* mImage;
qreal mZoom;
bool mZoomToFit;
......@@ -163,7 +162,6 @@ ImageView::ImageView(QWidget* parent)
{
d->mAlphaBackgroundMode = AlphaBackgroundCheckBoard;
d->mAlphaBackgroundColor = Qt::black;
d->mMouseWheelBehavior = MouseWheelScroll;
d->mImage = &d->mEmptyImage;
d->mView = this;
......@@ -201,16 +199,6 @@ void ImageView::setAlphaBackgroundColor(const QColor& color) {
}
void ImageView::setMouseWheelBehavior(ImageView::MouseWheelBehavior behavior) {
d->mMouseWheelBehavior = behavior;
}
ImageView::MouseWheelBehavior ImageView::mouseWheelBehavior() const {
return d->mMouseWheelBehavior;
}
void ImageView::setImage(const QImage* image) {
if (image) {
d->mImage = image;
......@@ -543,14 +531,4 @@ void ImageView::wheelEvent(QWheelEvent* event) {
}
void ImageView::emitPreviousImageRequested() {
emit previousImageRequested();
}
void ImageView::emitNextImageRequested() {
emit nextImageRequested();
}
} // namespace
......@@ -39,11 +39,6 @@ public:
AlphaBackgroundSolid
};
enum MouseWheelBehavior {
MouseWheelScroll,
MouseWheelBrowse
};
ImageView(QWidget* parent);
~ImageView();
......@@ -54,10 +49,6 @@ public:
void setAlphaBackgroundColor(const QColor& color);
void setMouseWheelBehavior(MouseWheelBehavior);
MouseWheelBehavior mouseWheelBehavior() const;
/**
* Set the image to display in this view. Note that we pass a pointer, not
* a reference, to make it more explicit that we do not keep a copy of the
......@@ -90,13 +81,8 @@ public:
QRect mapToViewport(const QRect& src);
QRect mapToImage(const QRect& src);
void emitPreviousImageRequested();
void emitNextImageRequested();
Q_SIGNALS:
void zoomChanged();
void previousImageRequested();
void nextImageRequested();
public Q_SLOTS:
void setZoomToFit(bool on);
......
......@@ -45,6 +45,8 @@ public Q_SLOTS:
Q_SIGNALS:
void resizeRequested(const QSize&);
void previousImageRequested();
void nextImageRequested();
};
} // namespace
......
......@@ -19,7 +19,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
// Self
#include "scrolltool.h"
#include "scrolltool.moc"
// Qt
#include <QApplication>
......@@ -35,6 +35,7 @@ namespace Gwenview {
struct ScrollToolPrivate {
ScrollTool::MouseWheelBehavior mMouseWheelBehavior;
int mScrollStartX;
int mScrollStartY;
bool mDragStarted;
......@@ -45,6 +46,7 @@ ScrollTool::ScrollTool(ImageView* view)
: AbstractImageViewTool(view)
, d(new ScrollToolPrivate) {
d->mDragStarted = false;
d->mMouseWheelBehavior = MouseWheelScroll;
}
......@@ -53,6 +55,16 @@ ScrollTool::~ScrollTool() {
}
void ScrollTool::setMouseWheelBehavior(ScrollTool::MouseWheelBehavior behavior) {
d->mMouseWheelBehavior = behavior;
}
ScrollTool::MouseWheelBehavior ScrollTool::mouseWheelBehavior() const {
return d->mMouseWheelBehavior;
}
void ScrollTool::mousePressEvent(QMouseEvent* event) {
if (imageView()->zoomToFit()) {
return;
......@@ -99,7 +111,7 @@ void ScrollTool::mouseReleaseEvent(QMouseEvent* /*event*/) {
void ScrollTool::wheelEvent(QWheelEvent* event) {
if (imageView()->mouseWheelBehavior() == ImageView::MouseWheelScroll) {
if (d->mMouseWheelBehavior == MouseWheelScroll) {
// Forward events to the scrollbars, like
// QAbstractScrollArea::wheelEvent() do.
if (event->orientation() == Qt::Horizontal) {
......@@ -110,9 +122,9 @@ void ScrollTool::wheelEvent(QWheelEvent* event) {
} else {
// Browse
if (event->delta() > 0) {
imageView()->emitPreviousImageRequested();
emit previousImageRequested();
} else {
imageView()->emitNextImageRequested();
emit nextImageRequested();
}
}
}
......
......@@ -35,7 +35,13 @@ namespace Gwenview {
class ScrollToolPrivate;
class GWENVIEWLIB_EXPORT ScrollTool : public AbstractImageViewTool {
Q_OBJECT
public:
enum MouseWheelBehavior {
MouseWheelScroll,
MouseWheelBrowse
};
ScrollTool(ImageView* view);
~ScrollTool();
......@@ -47,6 +53,13 @@ public:
virtual void toolActivated();
virtual void toolDeactivated();
void setMouseWheelBehavior(MouseWheelBehavior);
MouseWheelBehavior mouseWheelBehavior() const;
Q_SIGNALS:
void previousImageRequested();
void nextImageRequested();
private:
ScrollToolPrivate* const d;
};
......
......@@ -56,8 +56,14 @@ GVPart::GVPart(QWidget* parentWidget, QObject* parent, const QStringList& args)
mView = new ImageView(parentWidget);
setWidget(mView);
ScrollTool* scrollTool = new ScrollTool(mView);
mView->setCurrentTool(scrollTool);
mScrollTool = new ScrollTool(mView);
mView->setCurrentTool(mScrollTool);
connect(mScrollTool, SIGNAL(previousImageRequested()),
SIGNAL(previousImageRequested()) );
connect(mScrollTool, SIGNAL(nextImageRequested()),
SIGNAL(nextImageRequested()) );
mView->setContextMenuPolicy(Qt::CustomContextMenu);
mView->viewport()->installEventFilter(this);
connect(mView, SIGNAL(customContextMenuRequested(const QPoint&)),
......@@ -216,7 +222,7 @@ ImageView* GVPart::imageView() const {
void GVPart::loadConfig() {
mView->setAlphaBackgroundMode(GwenviewConfig::alphaBackgroundMode());
mView->setAlphaBackgroundColor(GwenviewConfig::alphaBackgroundColor());
mView->setMouseWheelBehavior(GwenviewConfig::mouseWheelBehavior());
mScrollTool->setMouseWheelBehavior(GwenviewConfig::mouseWheelBehavior());
}
......
......@@ -29,6 +29,7 @@ class KAction;
namespace Gwenview {
class ImageView;
class ScrollTool;
class GVPart : public ImageViewPart {
Q_OBJECT
......@@ -66,6 +67,7 @@ private:
Document::Ptr mDocument;
KAction* mZoomToFitAction;
bool mGwenviewHost;
ScrollTool* mScrollTool;
void disableZoomToFit();
void addPartSpecificActions();
......
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