diff options
author | Ken Moore <moorekou@gmail.com> | 2016-05-13 07:33:41 -0400 |
---|---|---|
committer | Ken Moore <moorekou@gmail.com> | 2016-05-13 07:33:41 -0400 |
commit | 80ec75948133283e0de56c341db243f917878736 (patch) | |
tree | 499e1174c0fb93120a2566879d20d39f3ecb64ce /src-qt5 | |
parent | Merge pull request #224 from HenryHu/skip_taskbar (diff) | |
parent | Move background processing into LDesktopBackground class (diff) | |
download | lumina-80ec75948133283e0de56c341db243f917878736.tar.gz lumina-80ec75948133283e0de56c341db243f917878736.tar.bz2 lumina-80ec75948133283e0de56c341db243f917878736.zip |
Merge pull request #223 from HenryHu/master
add 2 options for background image: fit and full
Diffstat (limited to 'src-qt5')
-rw-r--r-- | src-qt5/core-utils/lumina-config/mainUI.cpp | 2 | ||||
-rw-r--r-- | src-qt5/core/lumina-desktop/LDesktop.cpp | 15 | ||||
-rw-r--r-- | src-qt5/core/lumina-desktop/LDesktop.h | 3 | ||||
-rw-r--r-- | src-qt5/core/lumina-desktop/LDesktopBackground.cpp | 78 | ||||
-rw-r--r-- | src-qt5/core/lumina-desktop/LDesktopBackground.h | 27 | ||||
-rw-r--r-- | src-qt5/core/lumina-desktop/lumina-desktop.pro | 2 |
6 files changed, 113 insertions, 14 deletions
diff --git a/src-qt5/core-utils/lumina-config/mainUI.cpp b/src-qt5/core-utils/lumina-config/mainUI.cpp index 4bf067c5..5062a5ef 100644 --- a/src-qt5/core-utils/lumina-config/mainUI.cpp +++ b/src-qt5/core-utils/lumina-config/mainUI.cpp @@ -268,6 +268,8 @@ void MainUI::setupMenus(){ //Available Wallpaper layout options ui->combo_desk_layout->clear(); ui->combo_desk_layout->addItem(tr("Automatic"), "stretch"); + ui->combo_desk_layout->addItem(tr("Fullscreen"), "full"); + ui->combo_desk_layout->addItem(tr("Fit screen"), "fit"); ui->combo_desk_layout->addItem(tr("Tile"), "tile"); ui->combo_desk_layout->addItem(tr("Center"), "center"); ui->combo_desk_layout->addItem(tr("Top Left"), "topleft"); diff --git a/src-qt5/core/lumina-desktop/LDesktop.cpp b/src-qt5/core/lumina-desktop/LDesktop.cpp index 72b267b0..113b7efc 100644 --- a/src-qt5/core/lumina-desktop/LDesktop.cpp +++ b/src-qt5/core/lumina-desktop/LDesktop.cpp @@ -214,7 +214,7 @@ void LDesktop::InitDesktop(){ connect(QApplication::instance(), SIGNAL(LocaleChanged()), this, SLOT(LocaleChanged()) ); if(DEBUG){ qDebug() << "Create bgWindow"; } - bgWindow = new QWidget(); + bgWindow = new LDesktopBackground(); bgWindow->setObjectName("bgWindow"); bgWindow->setContextMenuPolicy(Qt::CustomContextMenu); bgWindow->setFocusPolicy(Qt::StrongFocus); @@ -500,19 +500,8 @@ void LDesktop::UpdateBackground(){ //qDebug() << " - Set Background to:" << CBG << index << bgL; if( (bgFile.toLower()=="default")){ bgFile = LOS::LuminaShare()+"desktop-background.jpg"; } //Now set this file as the current background - QString style; QString format = settings->value(DPREFIX+"background/format","stretch").toString(); - if(bgFile.startsWith("rgb(")){ style = "QWidget#bgWindow{ border-image: none; background-color: %1;}"; - }else if( format == "center"){ style = "QWidget#bgWindow{ background: black url(%1); background-position: center; background-repeat: no-repeat; }"; - }else if( format == "topleft"){ style = "QWidget#bgWindow{ background: black url(%1); background-position: top left; background-repeat: no-repeat; }"; - }else if( format == "topright"){ style = "QWidget#bgWindow{ background: black url(%1); background-position: top right; background-repeat: no-repeat; }"; - }else if( format == "bottomleft"){ style = "QWidget#bgWindow{ background: black url(%1); background-position: bottom left; background-repeat: no-repeat; }"; - }else if( format == "bottomright"){ style = "QWidget#bgWindow{ background: black url(%1); background-position: bottom right; background-repeat: no-repeat; }"; - }else if( format == "tile"){ style = "QWidget#bgWindow{ background-color: black; border-image:url(%1) repeat;}"; - }else{ /* STRETCH*/ style = "QWidget#bgWindow{ background-color: black; border-image:url(%1) stretch;}"; } - style = style.arg(bgFile); - bgWindow->setStyleSheet(style); - bgWindow->show(); + bgWindow->setBackground(bgFile, format); //Now reset the timer for the next change (if appropriate) if(bgtimer->isActive()){ bgtimer->stop(); } if(bgL.length() > 1){ diff --git a/src-qt5/core/lumina-desktop/LDesktop.h b/src-qt5/core/lumina-desktop/LDesktop.h index 14b6efc3..52505b12 100644 --- a/src-qt5/core/lumina-desktop/LDesktop.h +++ b/src-qt5/core/lumina-desktop/LDesktop.h @@ -31,6 +31,7 @@ #include "LDesktopPluginSpace.h" #include "desktop-plugins/LDPlugin.h" //#include "desktop-plugins/NewDP.h" +#include "LDesktopBackground.h" class LDesktop : public QObject{ Q_OBJECT @@ -67,7 +68,7 @@ private: QStringList oldBGL; QList<LPanel*> PANELS; LDesktopPluginSpace *bgDesktop; //desktop plugin area - QWidget *bgWindow; //full screen background + LDesktopBackground *bgWindow; //full screen background QMenu *deskMenu, *winMenu; QLabel *workspacelabel; QWidgetAction *wkspaceact; diff --git a/src-qt5/core/lumina-desktop/LDesktopBackground.cpp b/src-qt5/core/lumina-desktop/LDesktopBackground.cpp new file mode 100644 index 00000000..bdb6dbab --- /dev/null +++ b/src-qt5/core/lumina-desktop/LDesktopBackground.cpp @@ -0,0 +1,78 @@ +//=========================================== +// Lumina-DE source code +// Copyright (c) 2016, Henry Hu +// Available under the 3-clause BSD license +// See the LICENSE file for full details +//=========================================== +#include "LDesktopBackground.h" + +#include <QPainter> + +void LDesktopBackground::paintEvent(QPaintEvent *pe) { + if (bgPixmap != NULL) { + QPainter painter(this); + painter.setBrush(*bgPixmap); + painter.drawRect(0, 0, width(), height()); + } +} + +void LDesktopBackground::setBackground(const QString& bgFile, const QString& format) { + if (bgPixmap != NULL) delete bgPixmap; + bgPixmap = new QPixmap(size()); + + if (bgFile.startsWith("rgb(")) { + QStringList colors = bgFile.section(")",0,0).section("(",1,1).split(","); + QColor color = QColor(colors[0].toInt(), colors[1].toInt(), colors[2].toInt()); + bgPixmap->fill(color); + } else { + bgPixmap->fill(Qt::black); + + // Load the background file and scale + QPixmap bgImage(bgFile); + if (format == "stretch" || format == "full" || format == "fit") { + Qt::AspectRatioMode mode; + if (format == "stretch") { + mode = Qt::IgnoreAspectRatio; + } else if (format == "full") { + mode = Qt::KeepAspectRatioByExpanding; + } else { + mode = Qt::KeepAspectRatio; + } + bgImage = bgImage.scaled(size(), mode); + } + + // Calculate the offset + int dx = 0, dy = 0; + int drawWidth = bgImage.width(), drawHeight = bgImage.height(); + if (format == "fit" || format == "center" || format == "full") { + dx = (width() - bgImage.width()) / 2; + dy = (height() - bgImage.height()) / 2; + } else if (format == "tile") { + drawWidth = width(); + drawHeight = height(); + } else { + if (format.endsWith("right")) { + dx = width() - bgImage.width(); + } + if (format.startsWith("bottom")) { + dy = height() - bgImage.height(); + } + } + + // Draw the background image + QPainter painter(bgPixmap); + painter.setBrush(bgImage); + painter.setBrushOrigin(dx, dy); + painter.drawRect(dx, dy, drawWidth, drawHeight); + } + update(); + show(); +} + +LDesktopBackground::LDesktopBackground() : QWidget() { + bgPixmap = NULL; +} + +LDesktopBackground::~LDesktopBackground() { + if (bgPixmap != NULL) delete bgPixmap; +} diff --git a/src-qt5/core/lumina-desktop/LDesktopBackground.h b/src-qt5/core/lumina-desktop/LDesktopBackground.h new file mode 100644 index 00000000..a9ce64fa --- /dev/null +++ b/src-qt5/core/lumina-desktop/LDesktopBackground.h @@ -0,0 +1,27 @@ +//=========================================== +// Lumina-DE source code +// Copyright (c) 2016, Henry Hu +// Available under the 3-clause BSD license +// See the LICENSE file for full details +//=========================================== +#ifndef _LUMINA_DESKTOP_LDESKTOPBACKGROUND_H_ +#define _LUMINA_DESKTOP_LDESKTOPBACKGROUND_H_ + +#include <QString> +#include <QWidget> +#include <QPixmap> + +class LDesktopBackground: public QWidget { + Q_OBJECT +public: + LDesktopBackground(); + virtual ~LDesktopBackground(); + + virtual void paintEvent(QPaintEvent*); + void setBackground(const QString&, const QString&); + +private: + QPixmap *bgPixmap; +}; + +#endif // _LUMINA_DESKTOP_LDESKTOPBACKGROUND_H_ diff --git a/src-qt5/core/lumina-desktop/lumina-desktop.pro b/src-qt5/core/lumina-desktop/lumina-desktop.pro index cfc175ef..89053fda 100644 --- a/src-qt5/core/lumina-desktop/lumina-desktop.pro +++ b/src-qt5/core/lumina-desktop/lumina-desktop.pro @@ -19,6 +19,7 @@ SOURCES += main.cpp \ LXcbEventFilter.cpp \ LSession.cpp \ LDesktop.cpp \ + LDesktopBackground.cpp \ LDesktopPluginSpace.cpp \ LPanel.cpp \ LWinInfo.cpp \ @@ -34,6 +35,7 @@ HEADERS += Globals.h \ LXcbEventFilter.h \ LSession.h \ LDesktop.h \ + LDesktopBackground.h \ LDesktopPluginSpace.h \ LPanel.h \ LWinInfo.h \ |