summaryrefslogtreecommitdiff
path: root/src/previewimage.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/previewimage.cpp')
-rw-r--r--src/previewimage.cpp117
1 files changed, 94 insertions, 23 deletions
diff --git a/src/previewimage.cpp b/src/previewimage.cpp
index e7f8aea5..1c554cb9 100644
--- a/src/previewimage.cpp
+++ b/src/previewimage.cpp
@@ -49,6 +49,7 @@
#include <QMouseEvent>
#include <QHBoxLayout>
#include <QVBoxLayout>
+#include <QPainter>
PreviewImage::PreviewImage(const QUrl &url, const QString &title, int index, bool isFavorite)
@@ -62,17 +63,46 @@ PreviewImage::PreviewImage(const QUrl &url, const QString &title, int index, boo
, m_button(0)
, m_imageLabel(new QLabel)
, m_textLabel(new QLabel)
+ , m_backgroundLabel(new QLabel)
+ , m_previewLabel(new QLabel)
{
- setMinimumSize(300,200);
-
+
+ int borderTop = 14;
+ int borderRight = 16;
+ int borderBottom = 14;
+ int borderLeft = 16;
+
+ int previewWidth=200;
+ int previewHeight=150;
+
+ int urlHeight=18;
+
+ m_size = QSize(borderLeft+previewWidth+borderRight, borderTop+previewHeight+borderBottom+urlHeight);
+
+ setFixedSize(m_size);
+ m_previewLabel->setFixedSize(m_size);
+
+ m_backgroundLabel->setPixmap(renderBackground(previewWidth,previewHeight, borderTop, borderBottom, borderLeft, borderRight));
+
+ m_previewLabel->setAlignment(Qt::AlignCenter);
+ m_backgroundLabel->setAlignment(Qt::AlignCenter);
m_imageLabel->setAlignment(Qt::AlignCenter);
m_textLabel->setAlignment(Qt::AlignCenter);
-
- QVBoxLayout *mainLayout = new QVBoxLayout;
- mainLayout->addWidget(m_imageLabel);
- mainLayout->addWidget(m_textLabel);
- setLayout(mainLayout);
-
+
+ m_previewLabel->setLayout(new QVBoxLayout);
+ m_previewLabel->layout()->setMargin(0);
+ m_previewLabel->layout()->addWidget(m_backgroundLabel);
+ m_previewLabel->layout()->addWidget(m_textLabel);
+ m_previewLabel->setCursor(Qt::PointingHandCursor);
+
+ m_backgroundLabel->setLayout(new QVBoxLayout);
+ m_backgroundLabel->layout()->addWidget(m_imageLabel);
+
+ setLayout(new QHBoxLayout);
+ layout()->setMargin(0);
+ layout()->setAlignment(Qt::AlignCenter);
+ layout()->addWidget(m_previewLabel);
+
loadUrlPreview(url);
}
@@ -82,9 +112,38 @@ PreviewImage::~PreviewImage()
delete ws;
delete m_textLabel;
delete m_imageLabel;
+ delete m_backgroundLabel;
+ delete m_previewLabel;
}
+QPixmap PreviewImage::renderBackground(int w, int h, int t, int b, int l, int r)
+{
+ QImage backImage(KStandardDirs::locate("appdata", "pics/bg.png"));
+ QImage resultImage(QSize(w + l + r, h + t + b), QImage::Format_ARGB32_Premultiplied);
+
+ if (!backImage.isNull())
+ {
+ int sw = backImage.width() - l - r;
+ int sh = backImage.height() - t - b;
+ QPainter pt(&resultImage);
+ pt.setCompositionMode(QPainter::CompositionMode_Source);
+ pt.fillRect(resultImage.rect(), Qt::transparent);
+ pt.drawImage(QRect(0, 0, l, t), backImage, QRect(0, 0, l, t));
+ pt.drawImage(QRect(l, 0, w, t), backImage, QRect(l, 0, sw, t));
+ pt.drawImage(QRect(l + w, 0, r, t), backImage, QRect(l + sw, 0, r, t));
+ pt.drawImage(QRect(0, t, l, h), backImage, QRect(0, t, l, sh));
+ pt.drawImage(QRect(l, t, w, h), backImage, QRect(l, t, sw, sh));
+ pt.drawImage(QRect(l + w, t, r, h), backImage, QRect(l + sw, t, r, sh));
+ pt.drawImage(QRect(0, t + h, l , b), backImage, QRect(0, t + sh, l , b));
+ pt.drawImage(QRect(l, t + h, w, b), backImage, QRect(l, t + sh, sw, b));
+ pt.drawImage(QRect(l + w, t + h, w, b), backImage, QRect(l + sw, t + sh, sw, b));
+ pt.end();
+ }
+
+ return QPixmap::fromImage(resultImage);
+}
+
void PreviewImage::loadUrlPreview(const QUrl& url)
{
@@ -96,6 +155,8 @@ void PreviewImage::loadUrlPreview(const QUrl& url)
return;
}
+ m_previewLabel->setFixedSize(m_size); //unhide
+
m_savePath = KStandardDirs::locateLocal("cache", QString("thumbs/") + guessNameFromUrl(m_url) + ".png", true);
if(QFile::exists(m_savePath))
@@ -119,6 +180,7 @@ void PreviewImage::loadUrlPreview(const QUrl& url)
m_imageLabel->setMovie(movie);
movie->start();
m_textLabel->setText( i18n("Loading preview...") );
+ setCursor(Qt::BusyCursor);
}
}
@@ -129,17 +191,19 @@ void PreviewImage::snapFinished()
QMovie *m = m_imageLabel->movie();
delete m;
m_imageLabel->setMovie(0);
-
+
m_pixmap = ws->previewImage();
m_imageLabel->setPixmap(m_pixmap);
checkTitle();
m_textLabel->setText(m_title);
-
+
+ setCursor(Qt::PointingHandCursor);
+
// kDebug() << "m_pixmap: " << m_pixmap.size();
// kDebug() << "text label: " << m_textLabel->size();
// kDebug() << "image label: " << m_imageLabel->size();
// kDebug() << "widget: " << size();
-
+
m_pixmap.save(m_savePath);
if(m_index > -1)
@@ -149,7 +213,7 @@ void PreviewImage::snapFinished()
// update url (for added thumbs)
QStringList urls = ReKonfig::previewUrls();
- // stripTrailingSlash to be sure to get the same string for same adress
+ // stripTrailingSlash to be sure to get the same string for same address
urls.replace(m_index, ws->snapUrl().toString(QUrl::StripTrailingSlash));
names.replace(m_index, ws->snapTitle());
@@ -165,20 +229,21 @@ void PreviewImage::showEmptyPreview()
{
if(!m_isFavorite)
return;
-
+
m_imageLabel->clear();
m_textLabel->clear();
-
- QHBoxLayout *layout = new QHBoxLayout(m_imageLabel);
- m_button = new QToolButton(m_imageLabel);
+
+ m_previewLabel->setFixedSize(0,0); //hide
+
+
+ m_button = new QToolButton();
m_button->setDefaultAction(historyMenu());
m_button->setPopupMode(QToolButton::InstantPopup);
m_button->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
m_button->setText(i18n("Add Preview"));
m_button->setAutoRaise(true);
m_button->setIconSize(QSize(48, 48));
- layout->addWidget(m_button);
- m_imageLabel->setLayout(layout);
+ layout()->addWidget(m_button);
}
@@ -202,7 +267,13 @@ void PreviewImage::mousePressEvent(QMouseEvent *event)
{
Application::instance()->loadUrl(m_url);
return;
- };
+ }
+ else if(event->button() == Qt::MidButton)
+ {
+ Application::instance()->loadUrl(m_url, Rekonq::SettingOpenTab);
+ return;
+ }
+
QWidget::mousePressEvent(event);
}
@@ -243,12 +314,12 @@ void PreviewImage::contextMenuEvent(QContextMenuEvent* event)
KActionMenu* PreviewImage::historyMenu()
{
- KActionMenu *histMenu = new KActionMenu(KIcon("insert-image"), i18n("Set page to preview"), this);
+ KActionMenu *histMenu = new KActionMenu(KIcon("insert-image"), i18n("Set Page to Preview"), this);
QList<HistoryItem> history = Application::historyManager()->history();
if(history.isEmpty())
{
- KAction *a = new KAction(i18n("History is empty"), this);
+ KAction *a = new KAction(i18n("History is Empty"), this);
a->setEnabled(false);
histMenu->addAction(a);
return histMenu;
@@ -300,7 +371,7 @@ void PreviewImage::setUrlFromAction()
m_url = KUrl(urlData.at(0));
m_title = urlData.at(1);
checkTitle();
-
+
if(m_button)
{
m_imageLabel->layout()->deleteLater();
@@ -314,7 +385,7 @@ void PreviewImage::setUrlFromAction()
// update url (for added thumbs)
QStringList urls = ReKonfig::previewUrls();
- // stripTrailingSlash to be sure to get the same string for same adress
+ // stripTrailingSlash to be sure to get the same string for same address
urls.replace(m_index, m_url.toString(QUrl::StripTrailingSlash));
names.replace(m_index, m_title);