OSDN Git Service

Merge branch 'master' of ssh://nevernote.git.sourceforge.net/gitroot/nevernote/nevern...
[neighbornote/NeighborNote.git] / src / cx / fbn / nevernote / dialog / ThumbnailViewer.java
1 /*\r
2  * This file is part of NixNote \r
3  * Copyright 2009 Randy Baumgarte\r
4  * \r
5  * This file may be licensed under the terms of of the\r
6  * GNU General Public License Version 2 (the ``GPL'').\r
7  *\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
12  *\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
17  *\r
18 */\r
19 \r
20 package cx.fbn.nevernote.dialog;\r
21 \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
28 \r
29 import java.util.List;\r
30 \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
60         \r
61 \r
62         public ThumbnailViewer() {\r
63                 this.setVisible(false);\r
64                 \r
65                 leftArrow = new Signal0();\r
66                 rightArrow = new Signal0();\r
67                 upArrow = new Signal0();\r
68                 downArrow = new Signal0();\r
69 \r
70 \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
76             \r
77                 grid = new QGridLayout();\r
78                 setLayout(grid);\r
79                 \r
80                 \r
81                 picture = new QLabel();\r
82 /*              \r
83                 QLabel left = new QLabel();\r
84                 QLabel right = new QLabel();\r
85                 \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
91 */              \r
92                 \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
99 //              this.hide();\r
100 \r
101         }\r
102         public void setThumbnail(String thumb) {\r
103                 thumbnail = thumb;\r
104                 image = new QImage(thumbnail);\r
105                 picture.setPixmap(QPixmap.fromImage(image));\r
106         }\r
107         public void setThumbnail(QImage i) {\r
108                 image = i;\r
109                 picture.setPixmap(QPixmap.fromImage(image));\r
110         }\r
111         \r
112 \r
113         @Override\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
116                         upArrow.emit();\r
117                 }\r
118                 if (e.key() == Qt.Key.Key_Down.value() || e.key() == Qt.Key.Key_Left.value()) {\r
119                         downArrow.emit();\r
120                 }\r
121 \r
122                 super.keyPressEvent(e);\r
123         }\r
124         \r
125         \r
126         @Override\r
127         public void mousePressEvent(QMouseEvent e) {\r
128                 if (e.button() == Qt.MouseButton.LeftButton)\r
129                         close();\r
130         }\r
131         \r
132         @Override\r
133         public void wheelEvent(QWheelEvent e) {\r
134                 int numDegrees = e.delta() / 8;\r
135         int numSteps = numDegrees / 15;\r
136         \r
137         if (e.orientation().equals(Qt.Orientation.Vertical)) { \r
138                 if (numSteps > 0) {\r
139                         for (int i=0; i<numSteps; i++) {\r
140                                 upArrow.emit();\r
141                                 repaint();\r
142                         }\r
143                 }\r
144                 if (numSteps < 0) {\r
145                         for (int i=numSteps; i<0; i++) {\r
146                                 downArrow.emit();\r
147                                 repaint();\r
148                         }\r
149                 }\r
150         }\r
151         }\r
152         \r
153         @Override\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
160                 \r
161                 QPainter painter = new QPainter(this);\r
162                 \r
163                 painter.fillRect(desktop.screenGeometry(screen), QColor.black);\r
164 \r
165                 QRect availGeo = desktop.availableGeometry(screen);\r
166                 \r
167                 int x1 = (availGeo.width()/2)-(image.size().width()/2);\r
168                 int y1 = (availGeo.height()/2)-(image.size().height()/2);\r
169                 \r
170                 painter.drawImage(new QPoint(x1,y1), image);\r
171         }\r
172 \r
173 \r
174         public List<String> getGuids() {\r
175                 return guids;\r
176         }\r
177         public void setGuids(List<String> g) {\r
178                 guids = g;\r
179         }\r
180 \r
181 \r
182 }\r