mirror of
https://bitbucket.org/smil3y/kde-playground.git
synced 2025-02-23 18:32:51 +00:00
anipaper: new animated images wallpaper
Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
parent
c0650fe3f7
commit
a7571b058a
6 changed files with 158 additions and 2 deletions
|
@ -32,3 +32,4 @@ macro_optional_add_subdirectory (kfirewall)
|
||||||
macro_optional_add_subdirectory (khash)
|
macro_optional_add_subdirectory (khash)
|
||||||
macro_optional_add_subdirectory (kprintjobs)
|
macro_optional_add_subdirectory (kprintjobs)
|
||||||
macro_optional_add_subdirectory (xwallpaper)
|
macro_optional_add_subdirectory (xwallpaper)
|
||||||
|
macro_optional_add_subdirectory (anipaper)
|
||||||
|
|
26
anipaper/CMakeLists.txt
Normal file
26
anipaper/CMakeLists.txt
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
project(plasma-wallpaper-anipaper)
|
||||||
|
|
||||||
|
if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR})
|
||||||
|
include(FeatureSummary)
|
||||||
|
|
||||||
|
find_package(KDELibs4 4.23.0 REQUIRED)
|
||||||
|
|
||||||
|
include_directories(${KDE4_INCLUDES})
|
||||||
|
add_definitions(${QT_DEFINITIONS} ${KDE4_DEFINITIONS})
|
||||||
|
endif()
|
||||||
|
|
||||||
|
set(anipaper_SRCS
|
||||||
|
anipaper.cpp
|
||||||
|
)
|
||||||
|
|
||||||
|
kde4_add_plugin(plasma_wallpaper_anipaper ${anipaper_SRCS})
|
||||||
|
target_link_libraries(plasma_wallpaper_anipaper KDE4::plasma KDE4::kdeui)
|
||||||
|
|
||||||
|
install(
|
||||||
|
TARGETS plasma_wallpaper_anipaper
|
||||||
|
DESTINATION ${KDE4_PLUGIN_INSTALL_DIR}
|
||||||
|
)
|
||||||
|
install(
|
||||||
|
FILES plasma-wallpaper-anipaper.desktop
|
||||||
|
DESTINATION ${KDE4_SERVICES_INSTALL_DIR}
|
||||||
|
)
|
65
anipaper/anipaper.cpp
Normal file
65
anipaper/anipaper.cpp
Normal file
|
@ -0,0 +1,65 @@
|
||||||
|
/* This file is part of the KDE project
|
||||||
|
Copyright (C) 2023 Ivailo Monev <xakepa10@gmail.com>
|
||||||
|
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Library General Public
|
||||||
|
License version 2, as published by the Free Software Foundation.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Library General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Library General Public License
|
||||||
|
along with this library; see the file COPYING.LIB. If not, write to
|
||||||
|
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||||
|
Boston, MA 02110-1301, USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "anipaper.h"
|
||||||
|
|
||||||
|
#include <KDebug>
|
||||||
|
|
||||||
|
static const QString s_image = QString::fromLatin1("/home/smil3y/katana/kde-samples/image/3.webp");
|
||||||
|
static const Qt::AspectRatioMode s_aspect = Qt::KeepAspectRatio;
|
||||||
|
|
||||||
|
AniPaper::AniPaper(QObject *parent, const QVariantList &args)
|
||||||
|
: Plasma::Wallpaper(parent, args),
|
||||||
|
m_timer(nullptr),
|
||||||
|
m_imagereader(s_image)
|
||||||
|
{
|
||||||
|
if (m_imagereader.imageCount() <= 0) {
|
||||||
|
kWarning() << "No images in" << s_image;
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
kDebug() << "Started" << s_image << m_imagereader.nextImageDelay();
|
||||||
|
}
|
||||||
|
|
||||||
|
m_timer = new QTimer(this);
|
||||||
|
m_timer->setInterval(m_imagereader.nextImageDelay());
|
||||||
|
connect(m_timer, SIGNAL(timeout()), this, SLOT(slotTimeout()));
|
||||||
|
m_timer->start();
|
||||||
|
}
|
||||||
|
|
||||||
|
AniPaper::~AniPaper()
|
||||||
|
{
|
||||||
|
m_timer->stop();
|
||||||
|
}
|
||||||
|
|
||||||
|
void AniPaper::paint(QPainter *painter, const QRectF &exposedRect)
|
||||||
|
{
|
||||||
|
const QSize tsize = targetSizeHint().toSize();
|
||||||
|
QImage frame = m_imagereader.read().scaled(tsize, s_aspect, Qt::SmoothTransformation);
|
||||||
|
const QSize fsize = frame.size();
|
||||||
|
const QPoint offset = (QPoint(tsize.width() - fsize.width(), tsize.height() - fsize.height()) / 2);
|
||||||
|
kDebug() << "Rendering" << s_image << tsize << offset;
|
||||||
|
painter->drawImage(offset, frame);
|
||||||
|
}
|
||||||
|
|
||||||
|
void AniPaper::slotTimeout()
|
||||||
|
{
|
||||||
|
m_imagereader.jumpToNextImage();
|
||||||
|
emit update(QRectF());
|
||||||
|
}
|
||||||
|
|
||||||
|
#include "moc_anipaper.cpp"
|
47
anipaper/anipaper.h
Normal file
47
anipaper/anipaper.h
Normal file
|
@ -0,0 +1,47 @@
|
||||||
|
/* This file is part of the KDE project
|
||||||
|
Copyright (C) 2023 Ivailo Monev <xakepa10@gmail.com>
|
||||||
|
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Library General Public
|
||||||
|
License version 2, as published by the Free Software Foundation.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Library General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Library General Public License
|
||||||
|
along with this library; see the file COPYING.LIB. If not, write to
|
||||||
|
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||||
|
Boston, MA 02110-1301, USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef ANIPAPER_H
|
||||||
|
#define ANIPAPER_H
|
||||||
|
|
||||||
|
#include <QTimer>
|
||||||
|
#include <QImageReader>
|
||||||
|
#include <Plasma/Wallpaper>
|
||||||
|
#include <Plasma/DataEngine>
|
||||||
|
|
||||||
|
class AniPaper : public Plasma::Wallpaper
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
AniPaper(QObject *parent, const QVariantList &args);
|
||||||
|
~AniPaper();
|
||||||
|
|
||||||
|
void paint(QPainter* painter, const QRectF &exposedRect);
|
||||||
|
|
||||||
|
private Q_SLOTS:
|
||||||
|
void slotTimeout();
|
||||||
|
|
||||||
|
private:
|
||||||
|
QTimer* m_timer;
|
||||||
|
QImageReader m_imagereader;
|
||||||
|
};
|
||||||
|
|
||||||
|
K_EXPORT_PLASMA_WALLPAPER(anipaper, AniPaper)
|
||||||
|
|
||||||
|
#endif // ANIPAPER_H
|
17
anipaper/plasma-wallpaper-anipaper.desktop
Normal file
17
anipaper/plasma-wallpaper-anipaper.desktop
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
[Desktop Entry]
|
||||||
|
Name=Animated image wallpaper
|
||||||
|
Comment=Animated image wallpaper
|
||||||
|
Type=Service
|
||||||
|
Icon=tool-animator
|
||||||
|
ServiceTypes=Plasma/Wallpaper
|
||||||
|
|
||||||
|
X-KDE-Library=plasma_wallpaper_anipaper
|
||||||
|
X-KDE-PluginInfo-Author=Ivailo Monev
|
||||||
|
X-KDE-PluginInfo-Email=xakepa10@gmail.com
|
||||||
|
X-KDE-PluginInfo-Name=org.kde.anipaper
|
||||||
|
X-KDE-PluginInfo-Version=0.1
|
||||||
|
X-KDE-PluginInfo-Website=
|
||||||
|
X-KDE-PluginInfo-Depends=
|
||||||
|
X-KDE-PluginInfo-License=GPL
|
||||||
|
X-KDE-PluginInfo-EnabledByDefault=true
|
||||||
|
|
|
@ -34,7 +34,7 @@ XWallpaper::XWallpaper(QObject *parent, const QVariantList &args)
|
||||||
{
|
{
|
||||||
m_widget = new QWidget(nullptr, Qt::X11BypassWindowManagerHint);
|
m_widget = new QWidget(nullptr, Qt::X11BypassWindowManagerHint);
|
||||||
// move it outside the screen space, should the resolution change the widget may be visible but
|
// move it outside the screen space, should the resolution change the widget may be visible but
|
||||||
// neither rendering nor grabbing the window works without the winodow being visible
|
// neither rendering nor grabbing the window works without the window being visible
|
||||||
const QRect trect = QApplication::desktop()->geometry();
|
const QRect trect = QApplication::desktop()->geometry();
|
||||||
m_widget->move(trect.bottom(), trect.right());
|
m_widget->move(trect.bottom(), trect.right());
|
||||||
m_widget->show();
|
m_widget->show();
|
||||||
|
@ -67,8 +67,8 @@ XWallpaper::~XWallpaper()
|
||||||
|
|
||||||
void XWallpaper::paint(QPainter *painter, const QRectF &exposedRect)
|
void XWallpaper::paint(QPainter *painter, const QRectF &exposedRect)
|
||||||
{
|
{
|
||||||
kDebug() << "Rendering" << s_xscreensaver << targetSizeHint().toSize();
|
|
||||||
const QSize tsize = targetSizeHint().toSize();
|
const QSize tsize = targetSizeHint().toSize();
|
||||||
|
kDebug() << "Rendering" << s_xscreensaver << tsize;
|
||||||
m_widget->resize(tsize.width(), tsize.height());
|
m_widget->resize(tsize.width(), tsize.height());
|
||||||
painter->drawPixmap(QPoint(), QPixmap::grabWindow(m_widget->winId()));
|
painter->drawPixmap(QPoint(), QPixmap::grabWindow(m_widget->winId()));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue