[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: extragear/plasma/applets/frame
From: Thomas Coopman <thomas.coopman () gmail ! com>
Date: 2008-02-06 21:00:30
Message-ID: 1202331630.799388.15630.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 771740 by tcoopman:
Add i18n support for picture.cpp
Refactor the frame. Added a slideshow class
M +1 -0 CMakeLists.txt
M +1 -1 config.ui
M +39 -49 frame.cpp
M +10 -5 frame.h
M +14 -21 picture.cpp
M +4 -7 picture.h
--- trunk/extragear/plasma/applets/frame/CMakeLists.txt #771739:771740
@@ -2,6 +2,7 @@
set(frame_SRCS
frame.cpp
+ slideshow.cpp
picture.cpp)
--- trunk/extragear/plasma/applets/frame/config.ui #771739:771740
@@ -78,7 +78,7 @@
<bool>true</bool>
</property>
<property name="filter" >
- <string>*.png *.jpeg *.jpg</string>
+ <string>*.png *.jpeg *.jpg *.svg *.svgz</string>
</property>
</widget>
</item>
--- trunk/extragear/plasma/applets/frame/frame.cpp #771739:771740
@@ -1,6 +1,7 @@
/***************************************************************************
- * Copyright 2007 by Anne-Marie Mahfouf <annma@kde.org> *
- * Copyright 2007 by Antonio Vinci <mercurio@personellarete.it> *
+ * Copyright 2007 by Anne-Marie Mahfouf <annma@kde.org> *
+ * Copyright 2007 by Antonio Vinci <mercurio@personellarete.it> *
+ * Copyright 2008 by Thomas Coopman <thomas.coopman@gmail.com> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
@@ -46,6 +47,7 @@
#include <math.h>
#include "picture.h"
+#include "slideshow.h"
Frame::Frame(QObject *parent, const QVariantList &args)
: Plasma::Applet(parent, args),
@@ -56,8 +58,14 @@
setAcceptsHoverEvents(true);
setCachePaintMode(NoCacheMode);
setSize(350, 350);
+ m_mySlideShow = new SlideShow();
}
+Frame::~Frame()
+{
+ delete m_mySlideShow;
+}
+
void Frame::init()
{
m_dialog = 0;
@@ -68,10 +76,10 @@
m_frame = cg.readEntry("frame", false);
m_shadow = cg.readEntry("shadow", true);
m_roundCorners = cg.readEntry("roundCorners", false);
- m_slideShow = cg.readEntry("slideshow", false);
+ //m_slideShow = cg.readEntry("slideshow", false);
m_slideShowPaths = cg.readEntry("slideshow paths", QStringList());
m_slideshowTime = cg.readEntry("slideshow time", 10); // default to 10 seconds
- m_currentUrl = cg.readEntry("url", "Default");
+ //m_currentUrl = cg.readEntry("url", "Default");
// Frame & Shadow dimensions
m_frameOutline = 8;
@@ -79,15 +87,10 @@
// Initialize the slideshow timer
m_slideShowTimer = new QTimer(this);
- connect(m_slideShowTimer, SIGNAL(timeout()), this, SLOT(setSlideShow()));
+ connect(m_slideShowTimer, SIGNAL(timeout()), this, SLOT(updatePicture()));
m_slideShowTimer->setInterval(m_slideshowTime * 1000);
- if (m_slideShow) {
- setSlideShow();
- m_slideShowTimer->start();
- } else {
- choosePicture(m_currentUrl);
- }
+ initSlideShow();
}
void Frame::constraintsUpdated(Plasma::Constraints constraints)
@@ -97,29 +100,13 @@
}
}
-void Frame::setSlideShow()
+void Frame::updatePicture()
{
- Picture myPicture;
- QStringList picList=myPicture.findSlideShowPics(m_slideShowPaths);
- kDebug() <<"picList = " << picList <<endl;
- if (!picList.isEmpty()) {
- KUrl currentUrl(picList.at(m_slideNumber % picList.count()));
- m_slideNumber++;
- choosePicture(currentUrl);
- } else {
- choosePicture(m_currentUrl);
- }
+ m_picture = m_mySlideShow->getImage();
+ m_pixmapCache = QPixmap();
+ update();
}
-void Frame::choosePicture(const KUrl& currentUrl)
-{
- Picture myPicture;
- m_picture = myPicture.setPicture(contentSize().toSize().width(), currentUrl);
-
- m_pixmapCache = QPixmap();
- update();
-}
-
void Frame::addDir()
{
KDirSelectDialog dialog(KUrl(), true);
@@ -200,17 +187,24 @@
m_slideShowTimer->setInterval(m_slideshowTime * 1000);
cg.writeEntry("slideshow time", m_slideshowTime);
- if (m_slideShow) {
- setSlideShow();
- m_slideShowTimer->start();
- } else {
- m_slideShowTimer->stop();
- choosePicture(m_currentUrl);
- }
-
+ initSlideShow();
+
+
emit configNeedsSaving();
}
+void Frame::initSlideShow()
+{
+ if (m_slideShow) {
+ m_mySlideShow->setDirs(m_slideShowPaths);
+ m_slideShowTimer->start();
+ } else {
+ m_mySlideShow->setImage(m_currentUrl.path());
+ m_slideShowTimer->stop();
+ }
+ updatePicture();
+}
+
void Frame::dragEnterEvent(QGraphicsSceneDragDropEvent *event)
{
// kDebug() << event->mimeData()->formats();
@@ -226,22 +220,17 @@
KUrl droppedUrl = (KUrl::List::fromMimeData(event->mimeData())).at(0);
// If the url is a local directory start slideshowmode
if (droppedUrl.isLocalFile() && QFileInfo(droppedUrl.path()).isDir()) {
- if (!m_slideShowPaths.contains(droppedUrl.path())) {
- m_slideShowPaths.append(droppedUrl.path());
- if (!m_slideShow) {
- m_slideShow = true;
- setSlideShow();
- m_slideShowTimer->start();
- }
+ m_slideShowPaths.append(droppedUrl.path());
+ if (!m_slideShow) {
+ m_slideShow = true;
}
} else {
m_currentUrl = droppedUrl;
- choosePicture(m_currentUrl);
if (m_slideShow) {
- m_slideShowTimer->stop();
m_slideShow = false;
}
}
+ initSlideShow();
KConfigGroup cg = config();
cg.writeEntry("url", m_currentUrl);
@@ -275,7 +264,8 @@
QRect frameRect = m_pixmapCache.rect().adjusted(m_swOutline, m_swOutline,
-m_swOutline, -m_swOutline); \
//Pretty useless.
-
+
+ //TODO check if correct
QImage scaledImage = m_picture.scaled(frameRect.size(), Qt::KeepAspectRatio, \
Qt::FastTransformation);
frameRect = QRect(QPoint(frameRect.x() + (frameRect.width() - \
scaledImage.width()) / 2,
frameRect.y() + (frameRect.height() - scaledImage.height()) / \
2), scaledImage.size());
--- trunk/extragear/plasma/applets/frame/frame.h #771739:771740
@@ -1,6 +1,7 @@
/***************************************************************************
- * Copyright 2007 by Anne-Marie Mahfouf <annma@kde.org> *
- * Copyright 2007 by Antonio Vinci <mercurio@personellarete.it> *
+ * Copyright 2007 by Anne-Marie Mahfouf <annma@kde.org> *
+ * Copyright 2007 by Antonio Vinci <mercurio@personellarete.it> *
+ * Copyright 2008 by Thomas Coopman <thomas.coopman@gmail.com> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
@@ -37,6 +38,7 @@
class KDialog;
class QGraphicsSceneDragDropEvent;
+class SlideShow;
namespace Plasma
{
@@ -48,6 +50,7 @@
Q_OBJECT
public:
Frame(QObject *parent, const QVariantList &args);
+ ~Frame();
void paintInterface(QPainter *painter, const QStyleOptionGraphicsItem \
*option, const QRect &contentsRect);
@@ -61,8 +64,7 @@
void dropEvent(QGraphicsSceneDragDropEvent *event);
void dragEnterEvent(QGraphicsSceneDragDropEvent *event);
void configAccepted();
- void choosePicture(const KUrl& currentUrl);
- void setSlideShow();
+ void updatePicture();
private Q_SLOTS:
void addDir();
@@ -71,6 +73,7 @@
private:
void paintCache(const QStyleOptionGraphicsItem *option,
const QSize &contentsSize);
+ void initSlideShow();
/// The current color of the frame
QColor m_frameColor;
@@ -87,7 +90,6 @@
KUrl m_currentUrl;
/// The current slideshow folder
QStringList m_slideShowPaths;
- bool m_slideShow;
unsigned int m_slideNumber;
QTimer *m_slideShowTimer;
int m_slideshowTime;
@@ -100,6 +102,9 @@
int m_swOutline;
/// Designer Config file
Ui::config ui;
+ /// Slideshow
+ bool m_slideShow;
+ SlideShow* m_mySlideShow;
};
K_EXPORT_PLASMA_APPLET(frame, Frame)
--- trunk/extragear/plasma/applets/frame/picture.cpp #771739:771740
@@ -1,5 +1,6 @@
/***************************************************************************
* Copyright 2008 by Anne-Marie Mahfouf <annma@kde.org> *
+ * Copyright 2008 by Thomas Coopman <thomas.coopman@gmail.com> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
@@ -23,10 +24,15 @@
#include <QPainter>
#include <QPixmap>
#include <QSvgRenderer>
+#include <QTextDocument>
+#include <QTextOption>
#include <KUrl>
#include <KStandardDirs>
+#include <klocalizedstring.h>
+
+
Picture::Picture()
{
}
@@ -35,7 +41,7 @@
{
}
-QImage Picture::defaultPicture(int pixelSize, const QString &message)
+QImage Picture::defaultPicture(const QString &message)
{
// Create a QImage with same axpect ratio of default svg and current pixelSize
QString svgFile = Plasma::Theme::self()->image("widgets/picture-frame-default");
@@ -50,21 +56,24 @@
QFont textFont;
textFont.setPixelSize(imload.height() / 12);
p.setFont(textFont);
- p.drawText(imload.rect(), Qt::AlignCenter, message);
+ QTextOption option;
+ option.setAlignment(Qt::AlignCenter);
+ option.setWrapMode(QTextOption::WordWrap);
+ p.drawText(imload.rect(), message, option);
p.end();
return imload;
}
-QImage Picture::setPicture(int pixelSize, const KUrl ¤tUrl)
+QImage Picture::setPicture(const KUrl ¤tUrl)
{
QImage m_picture;
if (currentUrl.path() == "Default") {
- m_picture = defaultPicture(pixelSize, "Put your photo here\nor drop a folder\nfor \
starting a slideshow"); + m_picture = defaultPicture(i18nc("Info", "Put your photo \
here or drop a folder for starting a slideshow")); return m_picture;
} else {
QImage tempImage(currentUrl.path());
if (tempImage.isNull()){
- m_picture = defaultPicture(pixelSize, "Error loading image");
+ m_picture = defaultPicture(i18nc("Error", "Error loading image"));
return m_picture;
} else { // Load success! Scale the image if it is too big
if (tempImage.width() > m_maxDimension || tempImage.height() > \
m_maxDimension) { @@ -78,19 +87,3 @@
}
}
-QStringList Picture::findSlideShowPics(const QStringList &slideShowPaths)
-{
- QStringList picList;
-
- foreach (const QString &path, slideShowPaths) {
- QDir dir(path);
- QStringList filters;
- filters << "*.jpeg" << "*.jpg" << "*.png" << "*.svg" << "*.svgz"; // use \
mime types?
- dir.setNameFilters(filters);
- foreach (const QString &imageFile, dir.entryList(QDir::Files)) {
- picList.append(path + "/" + imageFile);
- }
- }
- return picList;
-}
-
--- trunk/extragear/plasma/applets/frame/picture.h #771739:771740
@@ -1,5 +1,6 @@
/***************************************************************************
* Copyright 2008 by Anne-Marie Mahfouf <annma@kde.org> *
+ * Copyright 2008 by Thomas Coopman <thomas.coopman@gmail.com> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
@@ -36,7 +37,7 @@
* makes it ready for the Frame class to paint this picture.
*/
-class Picture
+class Picture
{
public:
Picture();
@@ -45,15 +46,11 @@
* Set Default picture with written message @p message if no picture or folder was \
choosen
* by the user
**/
- QImage defaultPicture(int pixelSize, const QString &message);
+ QImage defaultPicture(const QString &message);
/**
* Set picture from location @p currentUrl
**/
- QImage setPicture(int pixelSize, const KUrl ¤tUrl);
- /**
- * Find all the pictures in each of the dirs that are listed in @p slideShowPaths
- **/
- QStringList findSlideShowPics(const QStringList &slideShowPaths);
+ QImage setPicture(const KUrl ¤tUrl);
private:
QImage getPicture(){return m_picture;};
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic