2 * This file is part of NeverNote
\r
3 * Copyright 2009 Randy Baumgarte
\r
5 * This file may be licensed under the terms of of the
\r
6 * GNU General Public License Version 2 (the ``GPL'').
\r
8 * Software distributed under the License is distributed
\r
9 * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
\r
10 * express or implied. See the GPL for the specific language
\r
11 * governing rights and limitations.
\r
13 * You should have received a copy of the GPL along with this
\r
14 * program. If not, go to http://www.gnu.org/licenses/gpl.html
\r
15 * or write to the Free Software Foundation, Inc.,
\r
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
\r
20 package cx.fbn.nevernote.dialog;
\r
22 import java.util.List;
\r
24 import com.trolltech.qt.core.QPoint;
\r
25 import com.trolltech.qt.core.QRect;
\r
26 import com.trolltech.qt.core.Qt;
\r
27 import com.trolltech.qt.core.Qt.WindowModality;
\r
28 import com.trolltech.qt.gui.QApplication;
\r
29 import com.trolltech.qt.gui.QColor;
\r
30 import com.trolltech.qt.gui.QDesktopWidget;
\r
31 import com.trolltech.qt.gui.QDialog;
\r
32 import com.trolltech.qt.gui.QGridLayout;
\r
33 import com.trolltech.qt.gui.QImage;
\r
34 import com.trolltech.qt.gui.QKeyEvent;
\r
35 import com.trolltech.qt.gui.QLabel;
\r
36 import com.trolltech.qt.gui.QMouseEvent;
\r
37 import com.trolltech.qt.gui.QPaintEvent;
\r
38 import com.trolltech.qt.gui.QPainter;
\r
39 import com.trolltech.qt.gui.QPalette;
\r
40 import com.trolltech.qt.gui.QPalette.ColorRole;
\r
41 import com.trolltech.qt.gui.QPixmap;
\r
42 import com.trolltech.qt.gui.QWheelEvent;
\r
43 public class ThumbnailViewer extends QDialog {
\r
44 private String thumbnail;
\r
45 private final QLabel picture;
\r
46 QGridLayout grid = new QGridLayout();
\r
47 public Signal0 upArrow;
\r
48 public Signal0 downArrow;
\r
49 public Signal0 leftArrow;
\r
50 public Signal0 rightArrow;
\r
51 private QImage image;
\r
52 private List<String> guids;
\r
55 public ThumbnailViewer() {
\r
56 this.setVisible(false);
\r
58 leftArrow = new Signal0();
\r
59 rightArrow = new Signal0();
\r
60 upArrow = new Signal0();
\r
61 downArrow = new Signal0();
\r
64 setAutoFillBackground(true);
\r
65 QPalette palette = new QPalette(palette());
\r
66 // Set background colour to black
\r
67 palette.setColor(ColorRole.Base, QColor.black);
\r
68 setPalette(palette);
\r
70 grid = new QGridLayout();
\r
74 picture = new QLabel();
\r
76 QLabel left = new QLabel();
\r
77 QLabel right = new QLabel();
\r
79 grid.addWidget(left, 0,0);
\r
80 grid.addWidget(picture,0,1);
\r
81 grid.addWidget(right, 0,2);
\r
82 grid.setWidgetSpacing(1);
\r
83 grid.setContentsMargins(10, 10, -10, -10);
\r
86 setWindowModality(WindowModality.ApplicationModal);
\r
87 setWindowFlags(Qt.WindowType.FramelessWindowHint);
\r
88 setAttribute(Qt.WidgetAttribute.WA_TranslucentBackground);
\r
89 // setBackgroundRole(ColorRole.Shadow);
\r
90 // setAttribute(Qt.WidgetAttribute.WA_DeleteOnClose);
\r
91 // showFullScreen();
\r
95 public void setThumbnail(String thumb) {
\r
97 image = new QImage(thumbnail);
\r
98 picture.setPixmap(QPixmap.fromImage(image));
\r
100 public void setThumbnail(QImage i) {
\r
102 picture.setPixmap(QPixmap.fromImage(image));
\r
107 public void keyPressEvent(QKeyEvent e) {
\r
108 if (e.key() == Qt.Key.Key_Up.value() || e.key() == Qt.Key.Key_Right.value()) {
\r
111 if (e.key() == Qt.Key.Key_Down.value() || e.key() == Qt.Key.Key_Left.value()) {
\r
115 super.keyPressEvent(e);
\r
120 public void mousePressEvent(QMouseEvent e) {
\r
121 if (e.button() == Qt.MouseButton.LeftButton)
\r
126 public void wheelEvent(QWheelEvent e) {
\r
127 int numDegrees = e.delta() / 8;
\r
128 int numSteps = numDegrees / 15;
\r
130 if (e.orientation().equals(Qt.Orientation.Vertical)) {
\r
131 if (numSteps > 0) {
\r
132 for (int i=0; i<numSteps; i++) {
\r
137 if (numSteps < 0) {
\r
138 for (int i=numSteps; i<0; i++) {
\r
147 public void paintEvent(QPaintEvent e) {
\r
148 QDesktopWidget desktop = QApplication.desktop();
\r
149 int screen = desktop.screenNumber();
\r
150 this.setMaximumSize(desktop.size());
\r
151 this.setMinimumSize(desktop.size());
\r
152 resize(desktop.size());
\r
154 QPainter painter = new QPainter(this);
\r
156 painter.fillRect(desktop.screenGeometry(screen), QColor.black);
\r
158 QRect availGeo = desktop.availableGeometry(screen);
\r
160 int x1 = (availGeo.width()/2)-(image.size().width()/2);
\r
161 int y1 = (availGeo.height()/2)-(image.size().height()/2);
\r
163 painter.drawImage(new QPoint(x1,y1), image);
\r
167 public List<String> getGuids() {
\r
170 public void setGuids(List<String> g) {
\r