aboutsummaryrefslogtreecommitdiff
path: root/src-qt5/core/lumina-desktop/desktop-plugins/applauncher
diff options
context:
space:
mode:
Diffstat (limited to 'src-qt5/core/lumina-desktop/desktop-plugins/applauncher')
-rw-r--r--src-qt5/core/lumina-desktop/desktop-plugins/applauncher/AppLauncherPlugin.cpp140
-rw-r--r--src-qt5/core/lumina-desktop/desktop-plugins/applauncher/AppLauncherPlugin.h59
-rw-r--r--src-qt5/core/lumina-desktop/desktop-plugins/applauncher/OutlineToolButton.h98
3 files changed, 297 insertions, 0 deletions
diff --git a/src-qt5/core/lumina-desktop/desktop-plugins/applauncher/AppLauncherPlugin.cpp b/src-qt5/core/lumina-desktop/desktop-plugins/applauncher/AppLauncherPlugin.cpp
new file mode 100644
index 00000000..101abd31
--- /dev/null
+++ b/src-qt5/core/lumina-desktop/desktop-plugins/applauncher/AppLauncherPlugin.cpp
@@ -0,0 +1,140 @@
+#include "AppLauncherPlugin.h"
+#include "../../LSession.h"
+#include "OutlineToolButton.h"
+
+#define OUTMARGIN 10 //special margin for fonts due to the outlining effect from the OutlineToolbutton
+
+AppLauncherPlugin::AppLauncherPlugin(QWidget* parent, QString ID) : LDPlugin(parent, ID){
+ QVBoxLayout *lay = new QVBoxLayout();
+ this->setLayout(lay);
+ lay->setContentsMargins(0,0,0,0);
+ button = new OutlineToolButton(this);
+ button->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
+ button->setAutoRaise(true);
+ button->setText("...\n..."); //Need to set something here so that initial sizing works properly
+ button->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding);
+ lay->addWidget(button, 0, Qt::AlignCenter);
+ connect(button, SIGNAL(DoubleClicked()), this, SLOT(buttonClicked()) );
+ button->setContextMenuPolicy(Qt::NoContextMenu);
+ watcher = new QFileSystemWatcher(this);
+ connect(watcher, SIGNAL(fileChanged(QString)), this, SLOT( loadButton()) );
+
+ QTimer::singleShot(200,this, SLOT(loadButton()) );
+}
+
+void AppLauncherPlugin::Cleanup(){
+ //This is run only when the plugin was forcibly closed/removed
+
+}
+
+void AppLauncherPlugin::loadButton(){
+ QString def = this->ID().section("::",1,50).section("---",0,0).simplified();
+ QString path = this->readSetting("applicationpath",def).toString(); //use the default if necessary
+ //qDebug() << "Default Application Launcher:" << def << path;
+ bool ok = QFile::exists(path);
+ if(!ok){ emit RemovePlugin(this->ID()); return;}
+ int icosize = this->height()-4 - 2.2*button->fontMetrics().height();
+ button->setFixedSize( this->width()-4, this->height()-4);
+ button->setIconSize( QSize(icosize,icosize) );
+ QString txt;
+ if(path.endsWith(".desktop") && ok){
+ XDGDesktop file = LXDG::loadDesktopFile(path, ok);
+ if(path.isEmpty() || !QFile::exists(path) || !ok){
+ button->setWhatsThis("");
+ button->setIcon( QIcon(LXDG::findIcon("quickopen-file","").pixmap(QSize(icosize,icosize)).scaledToHeight(icosize, Qt::SmoothTransformation) ) );
+ txt = tr("Click to Set");
+ if(!watcher->files().isEmpty()){ watcher->removePaths(watcher->files()); }
+ }else{
+ button->setWhatsThis(file.filePath);
+ button->setIcon( QIcon(LXDG::findIcon(file.icon,"quickopen").pixmap(QSize(icosize,icosize)).scaledToHeight(icosize, Qt::SmoothTransformation) ) );
+ txt = file.name;
+ if(!watcher->files().isEmpty()){ watcher->removePaths(watcher->files()); }
+ watcher->addPath(file.filePath); //make sure to update this shortcut if the file changes
+ }
+ }else if(ok){
+ QFileInfo info(path);
+ button->setWhatsThis(info.absoluteFilePath());
+ if(info.isDir()){
+ button->setIcon( LXDG::findIcon("folder","") );
+ }else if(LUtils::imageExtensions().contains(info.suffix().toLower()) ){
+ button->setIcon( QIcon(QPixmap(path).scaled(256,256)) ); //max size for thumbnails in memory
+ }else{
+ button->setIcon( QIcon(LXDG::findMimeIcon(path).pixmap(QSize(icosize,icosize)).scaledToHeight(icosize, Qt::SmoothTransformation) ) );
+ }
+ txt = info.fileName();
+ if(!watcher->files().isEmpty()){ watcher->removePaths(watcher->files()); }
+ watcher->addPath(path); //make sure to update this shortcut if the file changes
+ }else{
+ //InValid File
+ button->setWhatsThis("");
+ button->setIcon( QIcon(LXDG::findIcon("quickopen","").pixmap(QSize(icosize,icosize)).scaledToHeight(icosize, Qt::SmoothTransformation) ) );
+ button->setText( tr("Click to Set") );
+ if(!watcher->files().isEmpty()){ watcher->removePaths(watcher->files()); }
+ }
+ //If the file is a symlink, put the overlay on the icon
+ if(QFileInfo(path).isSymLink()){
+ QImage img = button->icon().pixmap(QSize(icosize,icosize)).toImage();
+ int oSize = icosize/3; //overlay size
+ QPixmap overlay = LXDG::findIcon("emblem-symbolic-link").pixmap(oSize,oSize).scaled(oSize,oSize, Qt::KeepAspectRatio, Qt::SmoothTransformation);
+ QPainter painter(&img);
+ painter.drawPixmap(icosize-oSize,icosize-oSize,overlay); //put it in the bottom-right corner
+ button->setIcon( QIcon(QPixmap::fromImage(img)) );
+ }
+ //Now adjust the visible text as necessary based on font/grid sizing
+ button->setToolTip(txt);
+ //Double check that the visual icon size matches the requested size - otherwise upscale the icon
+ if(button->fontMetrics().width(txt) > (button->width()-OUTMARGIN) ){
+ //Text too long, try to show it on two lines
+ //txt = button->fontMetrics().elidedText(txt, Qt::ElideRight, 2*(button->width()-OUTMARGIN), Qt::TextWordWrap);
+ txt =txt.section(" ",0,2).replace(" ","\n"); //First take care of any natural breaks
+ //Go through and combine any lines
+ if(txt.contains("\n")){
+ //need to check each line
+ QStringList txtL = txt.split("\n");
+ for(int i=0; i<txtL.length(); i++){
+ if(( i+1<txtL.length()) && (button->fontMetrics().width(txtL[i]) < button->width()/2) ){
+ txtL[i] = txtL[i]+" "+txtL[i+1];
+ txtL.removeAt(i+1);
+ }
+ }
+ txt = txtL.join("\n").section("\n",0,2);
+ }
+
+ if(txt.contains("\n")){
+ //need to check each line
+ QStringList txtL = txt.split("\n");
+ for(int i=0; i<txtL.length(); i++){
+ if(i>1){ txtL.removeAt(i); i--; } //Only take the first two lines
+ else{ txtL[i] = button->fontMetrics().elidedText(txtL[i], Qt::ElideRight, (button->width()-OUTMARGIN) ); }
+ }
+ txt = txtL.join("\n");
+ }else{
+ txt = this->fontMetrics().elidedText(txt,Qt::ElideRight, 2*(button->width()-OUTMARGIN));
+ //Now split the line in half for the two lines
+ txt.insert( ((txt.count())/2), "\n");
+ }
+ }
+ if(!txt.contains("\n")){ txt.append("\n "); } //always use two lines
+ //qDebug() << " - Setting Button Text:" << txt;
+ button->setText(txt);
+
+ QTimer::singleShot(100, this, SLOT(update()) ); //Make sure to re-draw the image in a moment
+}
+
+void AppLauncherPlugin::buttonClicked(){
+ QString path = button->whatsThis();
+ if(path.isEmpty() || !QFile::exists(path) ){
+ //prompt for the user to select an application
+ QList<XDGDesktop> apps = LXDG::sortDesktopNames( LXDG::systemDesktopFiles() );
+ QStringList names;
+ for(int i=0; i<apps.length(); i++){ names << apps[i].name; }
+ bool ok = false;
+ QString app = QInputDialog::getItem(this, tr("Select Application"), tr("Name:"), names, 0, false, &ok);
+ if(!ok || names.indexOf(app)<0){ return; } //cancelled
+ this->saveSetting("applicationpath", apps[ names.indexOf(app) ].filePath);
+ QTimer::singleShot(0,this, SLOT(loadButton()));
+ }else{
+ LSession::LaunchApplication("lumina-open \""+path+"\"");
+ }
+
+} \ No newline at end of file
diff --git a/src-qt5/core/lumina-desktop/desktop-plugins/applauncher/AppLauncherPlugin.h b/src-qt5/core/lumina-desktop/desktop-plugins/applauncher/AppLauncherPlugin.h
new file mode 100644
index 00000000..a0f6a7cd
--- /dev/null
+++ b/src-qt5/core/lumina-desktop/desktop-plugins/applauncher/AppLauncherPlugin.h
@@ -0,0 +1,59 @@
+//===========================================
+// Lumina-DE source code
+// Copyright (c) 2014, Ken Moore
+// Available under the 3-clause BSD license
+// See the LICENSE file for full details
+//===========================================
+// This class is a quick sample desktop plugin
+//===========================================
+#ifndef _LUMINA_DESKTOP_DESKTOP_PLUGIN_APPLICATION_LAUNCHER_H
+#define _LUMINA_DESKTOP_DESKTOP_PLUGIN_APPLICATION_LAUNCHER_H
+
+#include <QToolButton>
+#include <QInputDialog>
+#include <QVBoxLayout>
+#include <QProcess>
+#include <QFile>
+#include <QFileSystemWatcher>
+#include <QTimer>
+#include <QMenu>
+#include <QCursor>
+
+#include "../LDPlugin.h"
+
+#include <LuminaXDG.h>
+
+class AppLauncherPlugin : public LDPlugin{
+ Q_OBJECT
+public:
+ AppLauncherPlugin(QWidget* parent, QString ID);
+ ~AppLauncherPlugin(){}
+
+ void Cleanup(); //special function for final cleanup
+
+private:
+ QToolButton *button;
+ QFileSystemWatcher *watcher;
+ //QMenu *menu;
+
+private slots:
+ void loadButton();
+ void buttonClicked();
+ //void openContextMenu();
+
+ //void increaseIconSize();
+ //void decreaseIconSize();
+ //void deleteFile();
+
+public slots:
+ void LocaleChange(){
+ loadButton(); //force reload
+ }
+
+protected:
+ void resizeEvent(QResizeEvent *ev){
+ LDPlugin::resizeEvent(ev);
+ QTimer::singleShot(100, this, SLOT(loadButton()) );
+ }
+};
+#endif
diff --git a/src-qt5/core/lumina-desktop/desktop-plugins/applauncher/OutlineToolButton.h b/src-qt5/core/lumina-desktop/desktop-plugins/applauncher/OutlineToolButton.h
new file mode 100644
index 00000000..eaf9e23e
--- /dev/null
+++ b/src-qt5/core/lumina-desktop/desktop-plugins/applauncher/OutlineToolButton.h
@@ -0,0 +1,98 @@
+//===========================================
+// Lumina-DE source code
+// Copyright (c) 2015, Ken Moore
+// Available under the 3-clause BSD license
+// See the LICENSE file for full details
+//===========================================
+// This is a simple subclass for a QToolButton with black/white text (for transparent backgrounds)
+//===========================================
+#ifndef _LUMINA_DESKTOP_PLUGIN_APPLAUNCHER_OUTLINE_TOOLBUTTON_H
+#define _LUMINA_DESKTOP_PLUGIN_APPLAUNCHER_OUTLINE_TOOLBUTTON_H
+
+#include <QToolButton>
+#include <QPainter>
+#include <QPainterPath>
+#include <QPen>
+#include <QStyle>
+#include <QStyleOption>
+#include <QStylePainter>
+#include <QFont>
+#include <QDebug>
+#include <QMouseEvent>
+
+
+class OutlineToolButton : public QToolButton{
+ Q_OBJECT
+public:
+ OutlineToolButton(QWidget *parent=0) : QToolButton(parent){
+ //This button needs slightly different font settings - do this in the constructor so that other widgets can take it into account.
+ QFont font = this->font();
+ font.setStyleStrategy(QFont::PreferAntialias); //Always set the font strategy (just in case it starts working down the road)
+ this->setFont(font);
+ }
+ ~OutlineToolButton(){}
+
+signals:
+ void DoubleClicked();
+
+protected:
+ void mouseDoubleClickEvent(QMouseEvent *ev){
+ ev->accept();
+ emit DoubleClicked();
+ }
+ void mousePressEvent(QMouseEvent *ev){
+ ev->ignore();
+ }
+ void mouseReleaseEvent(QMouseEvent *ev){
+ ev->ignore();
+ }
+
+ void paintEvent(QPaintEvent*){
+ /* NOTE: This is what a standard QToolButton performs (peeked at Qt source code for this tidbit)
+ QStylePainter p(this);
+ QStyleOptionToolButton opt;
+ initStyleOption(&opt);
+ p.drawComplexControl(QStyle::CC_ToolButton, opt);
+ */
+
+ //Modify the standard QToolButton routine to paint the text differently
+ QStylePainter p(this);
+ QStyleOptionToolButton opt;
+ initStyleOption(&opt);
+ opt.font = this->property("font").value<QFont>(); //This ensures that the stylesheet values are incorporated
+ opt.font.setStyleStrategy(QFont::PreferAntialias); //Always set the font strategy (just in case it starts working down the road)
+ opt.font.setKerning(true);
+ opt.fontMetrics = QFontMetrics(opt.font);
+ opt.text.clear(); //Don't paint the text yet - just the background/icon
+ p.drawComplexControl(QStyle::CC_ToolButton, opt); //This does all the normal QToolButton stuff - just not text
+ //Now get the text rectangle for the widget
+ QRect box = p.style()->itemTextRect(opt.fontMetrics, opt.rect, Qt::AlignHCenter | Qt::AlignBottom, true, this->text());
+ //Get the QColors for the outline/text
+ QColor textC = opt.palette.text().color().toHsl(); //need the lightness value in a moment
+ QColor outC = textC;
+ //qDebug() << "Font Color Values:" << textC << textC.lightness() << textC.lightnessF();
+ if(textC.lightnessF() > 0.5){ outC.setHsl(textC.hue(), textC.hslSaturation(), 0, 90); }
+ else{outC.setHsl(textC.hue(), textC.hslSaturation(), 255, 50); }
+ //qDebug() << "Outline Color Values:" << outC;
+ //Now get the size of the outline border (need to scale for high-res monitors)
+ qreal OWidth = opt.fontMetrics.width("o")/2.0;
+ //qDebug() << "Outline Width:" << OWidth;
+ //Now generate a QPainterPath for the text
+ QPainterPath path;
+ QStringList txt = this->text().split("\n"); //need each line independently, the newline actually gets painted otherwise
+ for(int i=0; i<txt.length(); i++){
+ path.addText(box.center().x() - (opt.fontMetrics.width(txt[i])/2), box.y()+((i+1)*(box.height()/txt.length()))-opt.fontMetrics.descent(), opt.font, txt[i] );
+ }
+ path.setFillRule(Qt::WindingFill);
+ //Now paint the text
+ QRadialGradient RG(box.center(), box.width()*1.5); //width is always going to be greater than height
+ RG.setColorAt(0, outC);
+ RG.setColorAt(1, Qt::transparent);
+ p.setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing); //need antialiasing for this to work well (sub-pixel painting)
+ p.strokePath(path, QPen(QBrush(RG),OWidth, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin) ); //This will be the outline - 1pixel thick, semi-transparent
+ p.fillPath(path, QBrush(textC)); //this will be the inside/text color
+
+ }
+
+};
+#endif
bgstack15