From kde-commits Tue Jan 29 17:10:49 2008 From: Anne-Marie Mahfouf Date: Tue, 29 Jan 2008 17:10:49 +0000 To: kde-commits Subject: extragear/plasma/applets/frame Message-Id: <1201626649.190257.28216.nullmailer () svn ! kde ! org> X-MARC-Message: https://marc.info/?l=kde-commits&m=120162666009837 SVN commit 768280 by annma: choose a SVG for default pic so it can be themed - thanks to andruko for noti cing! M +1 -1 CMakeLists.txt M +1 -1 frame.cpp AM picture-frame-default.svg M +18 -11 picture.cpp M +5 -2 picture.h --- trunk/extragear/plasma/applets/frame/CMakeLists.txt #768279:768280 @@ -12,4 +12,4 @@ install(TARGETS plasma_applet_frame DESTINATION ${PLUGIN_INSTALL_DIR}) install(FILES plasma-frame-default.desktop DESTINATION ${SERVICES_INSTALL_DIR}) -install(FILES picture-frame-default.jpg DESTINATION ${DATA_INSTALL_DIR}/plasma-frame) +install(FILES picture-frame-default.svg DESTINATION ${DATA_INSTALL_DIR}/desktoptheme/default/widgets/) --- trunk/extragear/plasma/applets/frame/frame.cpp #768279:768280 @@ -116,7 +116,7 @@ void Frame::choosePicture(const KUrl& currentUrl) { Picture myPicture; - m_picture = myPicture.setPicture(currentUrl); + m_picture = myPicture.setPicture(contentSize().toSize().width(), currentUrl); m_pixmapCache = QPixmap(); update(); ** trunk/extragear/plasma/applets/frame/picture-frame-default.svg #property svn:eol-style + native --- trunk/extragear/plasma/applets/frame/picture.cpp #768279:768280 @@ -22,6 +22,7 @@ #include #include #include +#include #include #include @@ -35,33 +36,38 @@ { } -QImage Picture::defaultPicture(const QString &message) +QImage Picture::defaultPicture(int pixelSize, const QString &message) { // Create a QImage with same axpect ratio of default svg and current pixelSize - QString defaultFile = KGlobal::dirs()->findResource("data", "plasma-frame/picture-frame-default.jpg"); - QImage imload; - imload.load( defaultFile); - // Write message + QString svgFile = Plasma::Theme::self()->image("widgets/picture-frame-default"); + QSvgRenderer sr(svgFile); + QImage imload(sr.defaultSize(),QImage::Format_RGB32);//TODO optimize, too slow + QPainter p(&imload); + sr.render(&p, QRect(QPoint(0, 0), imload.size())); + + // Set the font and draw text p.setRenderHint(QPainter::Antialiasing); QFont textFont; - textFont.setPixelSize(imload.height() / 10); + textFont.setPixelSize(imload.height() / 12); p.setFont(textFont); p.drawText(imload.rect(), Qt::AlignCenter, message); p.end(); return imload; } -QImage Picture::setPicture(const KUrl ¤tUrl) +QImage Picture::setPicture(int pixelSize, const KUrl ¤tUrl) { + QImage m_picture; if (currentUrl.url().isEmpty()) { - return defaultPicture("Put your photo here\nor drop a folder\nfor starting a slideshow"); + m_picture = defaultPicture(pixelSize, "Put your photo here\nor drop a folder\nfor starting a slideshow"); + return m_picture; } else { QImage tempImage(currentUrl.path()); if (tempImage.isNull()){ - return defaultPicture("Error loading image"); - } else { // Load success! Scale the image if it is too big - QImage m_picture; + m_picture = defaultPicture(pixelSize, "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) { m_picture = tempImage.scaled(m_maxDimension,m_maxDimension, Qt::KeepAspectRatio,Qt::SmoothTransformation); @@ -88,3 +94,4 @@ } return picList; } + --- trunk/extragear/plasma/applets/frame/picture.h #768279:768280 @@ -23,7 +23,10 @@ #include #include +#include + class KUrl; +class QDir; /** * @brief Picture choice @@ -42,11 +45,11 @@ * Set Default picture with written message @p message if no picture or folder was choosen * by the user **/ - QImage defaultPicture(const QString &message); + QImage defaultPicture(int pixelSize, const QString &message); /** * Set picture from location @p currentUrl **/ - QImage setPicture( const KUrl ¤tUrl); + QImage setPicture(int pixelSize, const KUrl ¤tUrl); /** * Find all the pictures in each of the dirs that are listed in @p slideShowPaths **/