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
20 #include <QPushButton>
21 #include <QMainWindow>
26 class ImageScreen
: public QLabel
35 explicit ImageScreen(QWidget
* parent
)
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())
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())
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())
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())
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)
148 class MiniImageFrame
: public QWidget
153 QWidget
* Background
;
157 explicit MiniImageFrame(QWidget
* 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);
168 void FrameMoved(QPoint pos
);
171 void mousePressEvent(QMouseEvent
*event
)
175 PointOffset
= QPoint(0,y());
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
)
190 setGeometry(0,y(),width(),height());
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()));
232 class MiniImage
: public QWidget
238 MiniImageFrame
* MiniFrame
;
242 explicit MiniImage(QWidget
* parent
, QImage OriginalImage
)
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