summaryrefslogtreecommitdiff
path: root/noncore/graphics/drawpad/thumbnailview.cpp
Unidiff
Diffstat (limited to 'noncore/graphics/drawpad/thumbnailview.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/graphics/drawpad/thumbnailview.cpp29
1 files changed, 18 insertions, 11 deletions
diff --git a/noncore/graphics/drawpad/thumbnailview.cpp b/noncore/graphics/drawpad/thumbnailview.cpp
index 9b08ca2..90ba39c 100644
--- a/noncore/graphics/drawpad/thumbnailview.cpp
+++ b/noncore/graphics/drawpad/thumbnailview.cpp
@@ -18,24 +18,25 @@
18#include "newpagedialog.h" 18#include "newpagedialog.h"
19#include "page.h" 19#include "page.h"
20 20
21#include <qpe/config.h> 21#include <qpe/config.h>
22#include <qpe/resource.h> 22#include <qpe/resource.h>
23#include <qpe/timestring.h> 23#include <qpe/timestring.h>
24 24
25#include <qapplication.h> 25#include <qapplication.h>
26#include <qimage.h> 26#include <qimage.h>
27#include <qlayout.h> 27#include <qlayout.h>
28#include <qmessagebox.h> 28#include <qmessagebox.h>
29#include <qtoolbutton.h> 29#include <qtoolbutton.h>
30#include <qwhatsthis.h>
30 31
31#define THUMBNAIL_SIZE 48 32#define THUMBNAIL_SIZE 48
32 33
33PageListBoxItem::PageListBoxItem(Page* page, QListBox* parent) 34PageListBoxItem::PageListBoxItem(Page* page, QListBox* parent)
34 : QListBoxItem(parent) 35 : QListBoxItem(parent)
35{ 36{
36 m_pPage = page; 37 m_pPage = page;
37 38
38 QImage image = m_pPage->pixmap()->convertToImage(); 39 QImage image = m_pPage->pixmap()->convertToImage();
39 40
40 int previewWidth = THUMBNAIL_SIZE; 41 int previewWidth = THUMBNAIL_SIZE;
41 int previewHeight = THUMBNAIL_SIZE; 42 int previewHeight = THUMBNAIL_SIZE;
@@ -47,28 +48,29 @@ PageListBoxItem::PageListBoxItem(Page* page, QListBox* parent)
47 widthScale = (float)previewWidth / float(image.width()); 48 widthScale = (float)previewWidth / float(image.width());
48 } 49 }
49 50
50 if (previewHeight < image.height()) { 51 if (previewHeight < image.height()) {
51 heightScale = (float)previewHeight / float(image.height()); 52 heightScale = (float)previewHeight / float(image.height());
52 } 53 }
53 54
54 float scale = (widthScale < heightScale ? widthScale : heightScale); 55 float scale = (widthScale < heightScale ? widthScale : heightScale);
55 QImage thumbnailImage = image.smoothScale((int)(image.width() * scale) , (int)(image.height() * scale)); 56 QImage thumbnailImage = image.smoothScale((int)(image.width() * scale) , (int)(image.height() * scale));
56 57
57 m_thumbnail.convertFromImage(thumbnailImage); 58 m_thumbnail.convertFromImage(thumbnailImage);
58 59
59 m_titleText = QObject::tr("Title:") + " " + m_pPage->title(); 60 m_titleText = QObject::tr( "Title: %1" ).arg( m_pPage->title() );
60 m_dimensionText = QObject::tr("Dimension:") + " " + QString::number(m_pPage->pixmap()->width()) 61 m_dimensionText = QObject::tr( "Dimension: %1x%2" ).
61 + "x" + QString::number(m_pPage->pixmap()->height()); 62 arg( m_pPage->pixmap()->width() ).
62 m_dateText = QObject::tr("Date:") + " " + dateTimeString(m_pPage->lastModified()); 63 arg( m_pPage->pixmap()->height() );
64 m_dateText = QObject::tr( "Date: %1" ).arg( dateTimeString(m_pPage->lastModified()) );
63 65
64 QColor baseColor = parent->colorGroup().base(); 66 QColor baseColor = parent->colorGroup().base();
65 int h, s, v; 67 int h, s, v;
66 baseColor.hsv(&h, &s, &v); 68 baseColor.hsv(&h, &s, &v);
67 69
68 if (v > 128) { 70 if (v > 128) {
69 m_alternateColor = baseColor.dark(115); 71 m_alternateColor = baseColor.dark(115);
70 } else if (baseColor != Qt::black) { 72 } else if (baseColor != Qt::black) {
71 m_alternateColor = baseColor.light(115); 73 m_alternateColor = baseColor.light(115);
72 } else { 74 } else {
73 m_alternateColor = QColor(32, 32, 32); 75 m_alternateColor = QColor(32, 32, 32);
74 } 76 }
@@ -135,42 +137,42 @@ QString PageListBoxItem::dateTimeString(QDateTime dateTime)
135{ 137{
136 QString result; 138 QString result;
137 139
138 Config config("qpe"); 140 Config config("qpe");
139 config.setGroup("Date"); 141 config.setGroup("Date");
140 142
141 QChar separator = config.readEntry("Separator", "/")[0]; 143 QChar separator = config.readEntry("Separator", "/")[0];
142 DateFormat::Order shortOrder = (DateFormat::Order)config .readNumEntry("ShortOrder", DateFormat::DayMonthYear); 144 DateFormat::Order shortOrder = (DateFormat::Order)config .readNumEntry("ShortOrder", DateFormat::DayMonthYear);
143 145
144 for (int i = 0; i < 3; i++) { 146 for (int i = 0; i < 3; i++) {
145 switch((shortOrder >> (i * 3)) & 0x0007) { 147 switch((shortOrder >> (i * 3)) & 0x0007) {
146 case 0x0001: 148 case 0x0001:
147 result += QString().sprintf("%02d", dateTime.date().day()); 149 result.append( QString().sprintf("%02d", dateTime.date().day()) );
148 break; 150 break;
149 case 0x0002: 151 case 0x0002:
150 result += QString().sprintf("%02d", dateTime.date().month()); 152 result.append( QString().sprintf("%02d", dateTime.date().month()) );
151 break; 153 break;
152 case 0x0004: 154 case 0x0004:
153 result += QString().sprintf("%04d", dateTime.date().year()); 155 result.append( QString().sprintf("%04d", dateTime.date().year()) );
154 break; 156 break;
155 default: 157 default:
156 break; 158 break;
157 } 159 }
158 160
159 if (i < 2) { 161 if (i < 2) {
160 result += separator; 162 result.append( separator );
161 } 163 }
162 } 164 }
163 165
164 result += QString().sprintf(" %02d:%02d", dateTime.time().hour(), dateTime.time().minute()); 166 result.append( QString().sprintf(" %02d:%02d", dateTime.time().hour(), dateTime.time().minute()) );
165 167
166 return result; 168 return result;
167} 169}
168 170
169PageListBox::PageListBox(DrawPadCanvas* drawPadCanvas, QWidget* parent, const char* name) 171PageListBox::PageListBox(DrawPadCanvas* drawPadCanvas, QWidget* parent, const char* name)
170 : QListBox(parent, name) 172 : QListBox(parent, name)
171{ 173{
172 m_pDrawPadCanvas = drawPadCanvas; 174 m_pDrawPadCanvas = drawPadCanvas;
173 175
174 setVScrollBarMode(QScrollView::AlwaysOn); 176 setVScrollBarMode(QScrollView::AlwaysOn);
175 177
176 updateView(); 178 updateView();
@@ -220,57 +222,62 @@ Page* PageListBox::selected() const
220 PageListBoxItem* selectedItem = (PageListBoxItem*)item(currentItem()); 222 PageListBoxItem* selectedItem = (PageListBoxItem*)item(currentItem());
221 223
222 if (selectedItem) { 224 if (selectedItem) {
223 page = selectedItem->page(); 225 page = selectedItem->page();
224 } else { 226 } else {
225 page = NULL; 227 page = NULL;
226 } 228 }
227 229
228 return page; 230 return page;
229} 231}
230 232
231ThumbnailView::ThumbnailView(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas, QWidget* parent, const char* name) 233ThumbnailView::ThumbnailView(DrawPad* drawPad, DrawPadCanvas* drawPadCanvas, QWidget* parent, const char* name)
232 : QWidget(parent, name, Qt::WType_Modal | Qt::WType_TopLevel) 234 : QWidget(parent, name, Qt::WType_Modal | Qt::WType_TopLevel | Qt::WStyle_ContextHelp)
233{ 235{
234 inLoop = false; 236 inLoop = false;
235 237
236 m_pDrawPad = drawPad; 238 m_pDrawPad = drawPad;
237 m_pDrawPadCanvas = drawPadCanvas; 239 m_pDrawPadCanvas = drawPadCanvas;
238 240
239 setCaption(tr("DrawPad - Thumbnail View")); 241 setCaption(tr("DrawPad - Thumbnail View"));
240 242
241 QToolButton* newPageButton = new QToolButton(this); 243 QToolButton* newPageButton = new QToolButton(this);
242 newPageButton->setIconSet(Resource::loadIconSet("new")); 244 newPageButton->setIconSet(Resource::loadIconSet("new"));
243 newPageButton->setAutoRaise(true); 245 newPageButton->setAutoRaise(true);
244 connect(newPageButton, SIGNAL(clicked()), this, SLOT(newPage())); 246 connect(newPageButton, SIGNAL(clicked()), this, SLOT(newPage()));
247 QWhatsThis::add( newPageButton, tr( "Click here to add a new sheet." ) );
245 248
246 QToolButton* clearPageButton = new QToolButton(this); 249 QToolButton* clearPageButton = new QToolButton(this);
247 clearPageButton->setIconSet(Resource::loadIconSet("drawpad/clear")); 250 clearPageButton->setIconSet(Resource::loadIconSet("drawpad/clear"));
248 clearPageButton->setAutoRaise(true); 251 clearPageButton->setAutoRaise(true);
249 connect(clearPageButton, SIGNAL(clicked()), this, SLOT(clearPage())); 252 connect(clearPageButton, SIGNAL(clicked()), this, SLOT(clearPage()));
253 QWhatsThis::add( clearPageButton, tr( "Click here to erase the current sheet." ) );
250 254
251 QToolButton* deletePageButton = new QToolButton(this); 255 QToolButton* deletePageButton = new QToolButton(this);
252 deletePageButton->setIconSet(Resource::loadIconSet("trash")); 256 deletePageButton->setIconSet(Resource::loadIconSet("trash"));
253 deletePageButton->setAutoRaise(true); 257 deletePageButton->setAutoRaise(true);
254 connect(deletePageButton, SIGNAL(clicked()), this, SLOT(deletePage())); 258 connect(deletePageButton, SIGNAL(clicked()), this, SLOT(deletePage()));
259 QWhatsThis::add( deletePageButton, tr( "Click here to remove the current sheet." ) );
255 260
256 m_pMovePageUpButton = new QToolButton(this); 261 m_pMovePageUpButton = new QToolButton(this);
257 m_pMovePageUpButton->setIconSet(Resource::loadIconSet("up")); 262 m_pMovePageUpButton->setIconSet(Resource::loadIconSet("up"));
258 m_pMovePageUpButton->setAutoRaise(true); 263 m_pMovePageUpButton->setAutoRaise(true);
259 connect(m_pMovePageUpButton, SIGNAL(clicked()), this, SLOT(movePageUp())); 264 connect(m_pMovePageUpButton, SIGNAL(clicked()), this, SLOT(movePageUp()));
260 265 QWhatsThis::add( m_pMovePageUpButton, tr( "Click here to move the current sheet up one position in the list." ) );
266
261 m_pMovePageDownButton = new QToolButton(this); 267 m_pMovePageDownButton = new QToolButton(this);
262 m_pMovePageDownButton->setIconSet(Resource::loadIconSet("down")); 268 m_pMovePageDownButton->setIconSet(Resource::loadIconSet("down"));
263 m_pMovePageDownButton->setAutoRaise(true); 269 m_pMovePageDownButton->setAutoRaise(true);
264 connect(m_pMovePageDownButton, SIGNAL(clicked()), this, SLOT(movePageDown())); 270 connect(m_pMovePageDownButton, SIGNAL(clicked()), this, SLOT(movePageDown()));
271 QWhatsThis::add( m_pMovePageDownButton, tr( "Click here to move the current sheet down one position in the list." ) );
265 272
266 m_pPageListBox = new PageListBox(m_pDrawPadCanvas, this); 273 m_pPageListBox = new PageListBox(m_pDrawPadCanvas, this);
267 connect(m_pPageListBox, SIGNAL(selectionChanged()), this, SLOT(changePage())); 274 connect(m_pPageListBox, SIGNAL(selectionChanged()), this, SLOT(changePage()));
268 275
269 QVBoxLayout* mainLayout = new QVBoxLayout(this, 4, 4); 276 QVBoxLayout* mainLayout = new QVBoxLayout(this, 4, 4);
270 QHBoxLayout* buttonLayout = new QHBoxLayout(0); 277 QHBoxLayout* buttonLayout = new QHBoxLayout(0);
271 278
272 buttonLayout->addWidget(newPageButton); 279 buttonLayout->addWidget(newPageButton);
273 buttonLayout->addWidget(clearPageButton); 280 buttonLayout->addWidget(clearPageButton);
274 buttonLayout->addWidget(deletePageButton); 281 buttonLayout->addWidget(deletePageButton);
275 buttonLayout->addStretch(); 282 buttonLayout->addStretch();
276 buttonLayout->addWidget(m_pMovePageUpButton); 283 buttonLayout->addWidget(m_pMovePageUpButton);