Fixed bug #3 and some other bugs
[qallinone.git] / ImageViewerContents.h
blob0067e8e0525447886f46f3bac681cfe19cca98f3
1 /*qAllInOne is a free open-source software built using Qt to provide users an All-In-One media player, so it can view images, play videos and audio.
2 qAllInOne Copyright (C) 2013 Mahmoud Jaoune
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or any later version.
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
13 You should have received a copy of the GNU General Public License
14 along with this program. If not, see <http://www.gnu.org/licenses/>.*/
16 #ifndef IMAGEVIEWERCONTENTS_H
17 #define IMAGEVIEWERCONTENTS_H
19 #include <QtWidgets>
20 #include <QPushButton>
21 #include <QMainWindow>
22 #include <QLabel>
23 #include <QSlider>
24 #include <QImage>
26 class ImageScreen : public QLabel
28 Q_OBJECT
30 public:
32 QPoint PointOffset;
33 QWidget * Parent;
35 explicit ImageScreen(QWidget * parent)
37 setParent(parent);
38 Parent = parent;
41 public slots:
42 //Change cursor to Open Hand Cursor when zooming in is available and dragging image is possible
43 void enterEvent(QEvent *event)
45 if(this->width() > Parent->width() && this->height() > Parent->height())
47 QApplication::setOverrideCursor(Qt::OpenHandCursor);
51 //Change cursor to Default Pointer Cursor when mouse leaves the image area or dragging is not possible
52 void leaveEvent(QEvent *event)
54 QApplication::setOverrideCursor(Qt::ArrowCursor);
57 //Change cursor to Closed Hand Cursor when Image is clicked to be dragged
58 //Set the position of where the mouse clicked the image
59 void mousePressEvent(QMouseEvent *event)
61 if(this->width() > Parent->width() && this->height() > Parent->height())
63 QApplication::setOverrideCursor(Qt::ClosedHandCursor);
64 PointOffset = event->pos();
68 //Change cursor to Open Hand Cursor when Image is released
69 void mouseReleaseEvent(QMouseEvent *event)
71 if(this->width() > Parent->width() && this->height() > Parent->height())
73 QApplication::setOverrideCursor(Qt::OpenHandCursor);
77 //Move image when mouse is moved (Drag)
78 void mouseMoveEvent(QMouseEvent *event)
80 if(this->width() > Parent->width() && this->height() > Parent->height())
82 if(event->buttons() & Qt::LeftButton)
84 move(mapToParent(event->pos() - PointOffset));
89 //Limit image not to exceed bounds of MainWidget (Also MainWindow itself)
90 void moveEvent(QMoveEvent *event)
92 if(this->width() > Parent->width())
94 if(x() >= 0)
96 setGeometry(0,y(),width(),height());
98 else if(x() + width() <= Parent->width())
100 setGeometry(Parent->width() - width(),y(),width(),height());
104 if(this->height() > Parent->height())
106 if(y() >= 0)
108 setGeometry(x(),0,width(),height());
110 else if(y() + height() <= Parent->height())
112 setGeometry(x(),Parent->height() - height(),width(),height());
117 //Limit image not to exceed bounds of MainWidget (Also MainWindow itself) when resized (Zoomed in and out)
118 void resizeEvent(QResizeEvent * event)
120 if(this->width() > Parent->width())
122 if(x() >= 0)
124 setGeometry(0,y(),width(),height());
126 else if(x() + width() <= Parent->width())
128 setGeometry(Parent->width() - width(),y(),width(),height());
132 if(this->height() > Parent->height())
134 if(y() >= 0)
136 setGeometry(x(),0,width(),height());
138 else if(y() + height() <= Parent->height())
140 setGeometry(x(),Parent->height() - height(),width(),height());
146 //Experimental code of the MiniImage and MiniFrame featured (Unimplemented)
147 //MiniImageFrame
148 class MiniImageFrame : public QWidget
150 Q_OBJECT
152 public:
153 QWidget * Background;
154 QPoint PointOffset;
155 QWidget * Parent;
157 explicit MiniImageFrame(QWidget * parent)
159 setParent(parent);
160 Parent = parent;
161 Background = new QWidget(this);
162 Background->setGeometry(0,0,this->width(),this->height());
163 Background->setStyleSheet("* { background-color: rgb(255, 0, 0); }");
164 setMouseTracking(true);
167 signals:
168 void FrameMoved(QPoint pos);
170 public slots:
171 void mousePressEvent(QMouseEvent *event)
173 if(x() < 0)
175 PointOffset = QPoint(0,y());
177 if (y() < 0)
179 PointOffset = QPoint(x(),0);
181 else if((x() >= 0) && (y() >= 0)) PointOffset = event->pos();
184 void mouseMoveEvent(QMouseEvent *event)
186 if(event->buttons() & Qt::LeftButton)
188 if(x() < 0)
190 setGeometry(0,y(),width(),height());
192 if(y() < 0)
194 setGeometry(x(),0,width(),height());
197 else if((x() >= 0) && (y() >= 0))
199 move(mapToParent(event->pos() - PointOffset));
204 void moveEvent(QMoveEvent *event)
206 if(event->pos().x() <= 0)
208 setGeometry(0,y(),width(),height());
210 if(event->pos().y() <= 0)
212 setGeometry(x(),0,width(),height());
215 if(event->pos().x() >= (Parent->width() - width()))
217 setGeometry(Parent->width() - width(),y(),width(),height());
219 if(event->pos().y() >= (Parent->height() - height()))
221 setGeometry(x(),Parent->height() - height(),width(),height());
224 emit FrameMoved(QPoint(pos()));
231 //MiniImage
232 class MiniImage : public QWidget
234 Q_OBJECT
236 public:
237 QLabel * Background;
238 MiniImageFrame * MiniFrame;
239 QImage ScaledImage;
242 explicit MiniImage(QWidget * parent, QImage OriginalImage)
244 setParent(parent);
246 Background = new QLabel(this);
248 ScaledImage = OriginalImage.scaled(128,64,Qt::KeepAspectRatio,Qt::SmoothTransformation);
250 setBaseSize(ScaledImage.width(),ScaledImage.height());
252 Background->setPixmap(QPixmap::fromImage(ScaledImage,Qt::AutoColor));
253 Background->setGeometry(0,0,ScaledImage.width(),ScaledImage.height());
256 MiniFrame = new MiniImageFrame(Background);
257 MiniFrame->setGeometry(0,0,ScaledImage.width(),ScaledImage.height());
263 //End of unimplemented code
265 #endif // IMAGEVIEWERCONTENTS_H