2 * This file is part of NixNote
\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 //**********************************************
\r
23 //**********************************************
\r
24 //* This isn't really used but at one time it
\r
25 //* was used to create a full page preview.
\r
26 //**********************************************
\r
27 //**********************************************
\r
29 import java.util.List;
\r
31 import com.trolltech.qt.core.QPoint;
\r
32 import com.trolltech.qt.core.QRect;
\r
33 import com.trolltech.qt.core.Qt;
\r
34 import com.trolltech.qt.core.Qt.WindowModality;
\r
35 import com.trolltech.qt.gui.QApplication;
\r
36 import com.trolltech.qt.gui.QColor;
\r
37 import com.trolltech.qt.gui.QDesktopWidget;
\r
38 import com.trolltech.qt.gui.QDialog;
\r
39 import com.trolltech.qt.gui.QGridLayout;
\r
40 import com.trolltech.qt.gui.QImage;
\r
41 import com.trolltech.qt.gui.QKeyEvent;
\r
42 import com.trolltech.qt.gui.QLabel;
\r
43 import com.trolltech.qt.gui.QMouseEvent;
\r
44 import com.trolltech.qt.gui.QPaintEvent;
\r
45 import com.trolltech.qt.gui.QPainter;
\r
46 import com.trolltech.qt.gui.QPalette;
\r
47 import com.trolltech.qt.gui.QPalette.ColorRole;
\r
48 import com.trolltech.qt.gui.QPixmap;
\r
49 import com.trolltech.qt.gui.QWheelEvent;
\r
50 public class ThumbnailViewer extends QDialog {
\r
51 private String thumbnail;
\r
52 private final QLabel picture;
\r
53 QGridLayout grid = new QGridLayout();
\r
54 public Signal0 upArrow;
\r
55 public Signal0 downArrow;
\r
56 public Signal0 leftArrow;
\r
57 public Signal0 rightArrow;
\r
58 private QImage image;
\r
59 private List<String> guids;
\r
62 public ThumbnailViewer() {
\r
63 this.setVisible(false);
\r
65 leftArrow = new Signal0();
\r
66 rightArrow = new Signal0();
\r
67 upArrow = new Signal0();
\r
68 downArrow = new Signal0();
\r
71 setAutoFillBackground(true);
\r
72 QPalette palette = new QPalette(palette());
\r
73 // Set background colour to black
\r
74 palette.setColor(ColorRole.Base, QColor.black);
\r
75 setPalette(palette);
\r
77 grid = new QGridLayout();
\r
81 picture = new QLabel();
\r
83 QLabel left = new QLabel();
\r
84 QLabel right = new QLabel();
\r
86 grid.addWidget(left, 0,0);
\r
87 grid.addWidget(picture,0,1);
\r
88 grid.addWidget(right, 0,2);
\r
89 grid.setWidgetSpacing(1);
\r
90 grid.setContentsMargins(10, 10, -10, -10);
\r
93 setWindowModality(WindowModality.ApplicationModal);
\r
94 setWindowFlags(Qt.WindowType.FramelessWindowHint);
\r
95 setAttribute(Qt.WidgetAttribute.WA_TranslucentBackground);
\r
96 // setBackgroundRole(ColorRole.Shadow);
\r
97 // setAttribute(Qt.WidgetAttribute.WA_DeleteOnClose);
\r
98 // showFullScreen();
\r
102 public void setThumbnail(String thumb) {
\r
104 image = new QImage(thumbnail);
\r
105 picture.setPixmap(QPixmap.fromImage(image));
\r
107 public void setThumbnail(QImage i) {
\r
109 picture.setPixmap(QPixmap.fromImage(image));
\r
114 public void keyPressEvent(QKeyEvent e) {
\r
115 if (e.key() == Qt.Key.Key_Up.value() || e.key() == Qt.Key.Key_Right.value()) {
\r
118 if (e.key() == Qt.Key.Key_Down.value() || e.key() == Qt.Key.Key_Left.value()) {
\r
122 super.keyPressEvent(e);
\r
127 public void mousePressEvent(QMouseEvent e) {
\r
128 if (e.button() == Qt.MouseButton.LeftButton)
\r
133 public void wheelEvent(QWheelEvent e) {
\r
134 int numDegrees = e.delta() / 8;
\r
135 int numSteps = numDegrees / 15;
\r
137 if (e.orientation().equals(Qt.Orientation.Vertical)) {
\r
138 if (numSteps > 0) {
\r
139 for (int i=0; i<numSteps; i++) {
\r
144 if (numSteps < 0) {
\r
145 for (int i=numSteps; i<0; i++) {
\r
154 public void paintEvent(QPaintEvent e) {
\r
155 QDesktopWidget desktop = QApplication.desktop();
\r
156 int screen = desktop.screenNumber();
\r
157 this.setMaximumSize(desktop.size());
\r
158 this.setMinimumSize(desktop.size());
\r
159 resize(desktop.size());
\r
161 QPainter painter = new QPainter(this);
\r
163 painter.fillRect(desktop.screenGeometry(screen), QColor.black);
\r
165 QRect availGeo = desktop.availableGeometry(screen);
\r
167 int x1 = (availGeo.width()/2)-(image.size().width()/2);
\r
168 int y1 = (availGeo.height()/2)-(image.size().height()/2);
\r
170 painter.drawImage(new QPoint(x1,y1), image);
\r
174 public List<String> getGuids() {
\r
177 public void setGuids(List<String> g) {
\r