From 9aa35401ade8779dddd63dd8726c2755a751d047 Mon Sep 17 00:00:00 2001 From: Ken Moore Date: Tue, 13 Oct 2015 11:53:38 -0400 Subject: A bit more cleanup of the new desktop icons: 1) Adjust the font outlines quite a bit more - now it properly respects the theme settings and adjusts appropriately. 2) Add options to re-size all the desktop icons at the same time (use 16 pixel increments) 3) Adjust the default desktop icon size (use a 64x64 icon be default). 4) Ensure that the applauncher re-scales the icon as necessary to ensure it is the proper size. --- lumina-desktop/LDesktop.cpp | 19 +++++++++++++++++- lumina-desktop/LDesktop.h | 2 ++ lumina-desktop/LDesktopPluginSpace.cpp | 23 ++++++++++++++++++---- lumina-desktop/LDesktopPluginSpace.h | 4 +++- lumina-desktop/desktop-plugins/LDPlugin.cpp | 3 +++ lumina-desktop/desktop-plugins/LDPlugin.h | 2 ++ .../applauncher/AppLauncherPlugin.cpp | 8 +++++++- .../applauncher/OutlineToolButton.h | 14 ++++++++----- 8 files changed, 63 insertions(+), 12 deletions(-) (limited to 'lumina-desktop') diff --git a/lumina-desktop/LDesktop.cpp b/lumina-desktop/LDesktop.cpp index 0b207e0a..5563164f 100644 --- a/lumina-desktop/LDesktop.cpp +++ b/lumina-desktop/LDesktop.cpp @@ -224,8 +224,10 @@ void LDesktop::InitDesktop(){ connect(bgWindow, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(ShowMenu(const QPoint&)) ); if(DEBUG){ qDebug() << "Create bgDesktop"; } bgDesktop = new LDesktopPluginSpace(bgWindow); //new QMdiArea(bgWindow); - bgDesktop->SetIconSize(qRound(bgWindow->height()/14.0)); // (For 1600x900 screens - this comes out to 64 pixel icons) + bgDesktop->SetIconSize( settings->value(DPREFIX+"IconSize",64).toInt() ); connect(bgDesktop, SIGNAL(PluginRemovedByUser(QString)), this, SLOT(RemoveDeskPlugin(QString)) ); + connect(bgDesktop, SIGNAL(IncreaseIcons()), this, SLOT(IncreaseDesktopPluginIcons()) ); + connect(bgDesktop, SIGNAL(DecreaseIcons()), this, SLOT(DecreaseDesktopPluginIcons()) ); if(DEBUG){ qDebug() << " - Desktop Init Done:" << desktopnumber; } //Start the update processes QTimer::singleShot(10,this, SLOT(UpdateMenu()) ); @@ -369,6 +371,21 @@ void LDesktop::RemoveDeskPlugin(QString ID){ } } +void LDesktop::IncreaseDesktopPluginIcons(){ + int cur = settings->value(DPREFIX+"IconSize",64).toInt(); + cur+=16; + settings->setValue(DPREFIX+"IconSize",cur); + bgDesktop->SetIconSize(cur); +} + +void LDesktop::DecreaseDesktopPluginIcons(){ + int cur = settings->value(DPREFIX+"IconSize",64).toInt(); + if(cur<32){ return; } //cannot get smaller than 16x16 + cur-=16; + settings->setValue(DPREFIX+"IconSize",cur); + bgDesktop->SetIconSize(cur); +} + void LDesktop::UpdatePanels(){ if(DEBUG){ qDebug() << " - Update Panels For Screen:" << desktopnumber; } int panels = settings->value(DPREFIX+"panels", -1).toInt(); diff --git a/lumina-desktop/LDesktop.h b/lumina-desktop/LDesktop.h index 041f4ba5..55f31cd7 100644 --- a/lumina-desktop/LDesktop.h +++ b/lumina-desktop/LDesktop.h @@ -95,6 +95,8 @@ private slots: //Desktop plugin system functions void UpdateDesktop(); void RemoveDeskPlugin(QString); + void IncreaseDesktopPluginIcons(); + void DecreaseDesktopPluginIcons(); void UpdatePanels(); diff --git a/lumina-desktop/LDesktopPluginSpace.cpp b/lumina-desktop/LDesktopPluginSpace.cpp index 243afd24..5668843a 100644 --- a/lumina-desktop/LDesktopPluginSpace.cpp +++ b/lumina-desktop/LDesktopPluginSpace.cpp @@ -45,7 +45,7 @@ void LDesktopPluginSpace::SetIconSize(int size){ itemSize = newsize; //save this for all the later icons which are generated (grid size) UpdateGeom(); //Now re-set the item icon size - QTimer::singleShot(0,this, SLOT(reloadPlugins()) ); + reloadPlugins(true); } void LDesktopPluginSpace::cleanup(){ @@ -73,7 +73,7 @@ QSize LDesktopPluginSpace::calculateItemSize(int icosize){ QSize sz; sz.setWidth(1.8*icosize); sz.setWidth( RoundUp(sz.width()/GRIDSIZE)); //always round up to cell numbers - sz.setHeight(icosize+ 2.3*this->fontMetrics().height() ); + sz.setHeight(icosize+ 2.1*this->fontMetrics().height() ); sz.setHeight( RoundUp(sz.height()/GRIDSIZE)); //always round up to cell number return sz; } @@ -114,6 +114,8 @@ void LDesktopPluginSpace::addDesktopPlugin(QString plugID){ connect(plug, SIGNAL(StartMoving(QString)), this, SLOT(StartItemMove(QString)) ); connect(plug, SIGNAL(StartResizing(QString)), this, SLOT(StartItemResize(QString)) ); connect(plug, SIGNAL(RemovePlugin(QString)), this, SLOT(RemoveItem(QString)) ); + connect(plug, SIGNAL(IncreaseIconSize()), this, SIGNAL(IncreaseIcons()) ); + connect(plug, SIGNAL(DecreaseIconSize()), this, SIGNAL(DecreaseIcons()) ); } } @@ -184,7 +186,7 @@ QPoint LDesktopPluginSpace::findOpenSpot(int gridwidth, int gridheight, int star // =================== // PRIVATE SLOTS // =================== -void LDesktopPluginSpace::reloadPlugins(){ +void LDesktopPluginSpace::reloadPlugins(bool ForceIconUpdate ){ //Remove any plugins as necessary QStringList plugs = plugins; QStringList items = deskitems; @@ -192,7 +194,20 @@ void LDesktopPluginSpace::reloadPlugins(){ if(plugs.contains(ITEMS[i]->whatsThis())){ plugs.removeAll(ITEMS[i]->whatsThis()); } else if(ITEMS[i]->whatsThis().contains("---dlink") && items.contains(ITEMS[i]->whatsThis().section("---",0,0).section("::",1,50)) ){ //Account for the variation in the Plugin ID for desktop files - items.removeAll(ITEMS[i]->whatsThis().section("---",0,0).section("::",1,50)); + if(ForceIconUpdate){ + //Change the size of the existing plugin - preserving the location if possible + QRect geom = ITEMS[i]->loadPluginGeometry(); + if(!geom.isNull()){ + geom.setSize(itemSize); //Reset back to default size (does not change location) + ITEMS[i]->savePluginGeometry(geom); + } + //Now remove the plugin for the moment - run it through the re-creation routine below + delete ITEMS.takeAt(i); + i--; + }else{ + items.removeAll(ITEMS[i]->whatsThis().section("---",0,0).section("::",1,50)); + } + }else{ ITEMS[i]->removeSettings(true); delete ITEMS.takeAt(i); i--; } //this is considered a permanent removal (cleans settings) } diff --git a/lumina-desktop/LDesktopPluginSpace.h b/lumina-desktop/LDesktopPluginSpace.h index bf623b68..842999b3 100644 --- a/lumina-desktop/LDesktopPluginSpace.h +++ b/lumina-desktop/LDesktopPluginSpace.h @@ -28,6 +28,8 @@ class LDesktopPluginSpace : public QWidget{ signals: void PluginRemovedByUser(QString ID); + void IncreaseIcons(); //increase default icon sizes + void DecreaseIcons(); //decrease default icon sizes public: LDesktopPluginSpace(QWidget *parent = 0); @@ -125,7 +127,7 @@ private: } private slots: - void reloadPlugins(); + void reloadPlugins(bool ForceIconUpdate = false); void StartItemMove(QString ID){ setupDrag(ID, "move"); diff --git a/lumina-desktop/desktop-plugins/LDPlugin.cpp b/lumina-desktop/desktop-plugins/LDPlugin.cpp index c6d2e320..0fec17c6 100644 --- a/lumina-desktop/desktop-plugins/LDPlugin.cpp +++ b/lumina-desktop/desktop-plugins/LDPlugin.cpp @@ -36,6 +36,9 @@ void LDPlugin::setupMenu(){ menu->addAction( LXDG::findIcon("transform-move",""), tr("Start Moving Item"), this, SLOT(slotStartMove()) ); menu->addAction( LXDG::findIcon("transform-scale",""), tr("Start Resizing Item"), this, SLOT(slotStartResize()) ); menu->addSeparator(); + menu->addAction( LXDG::findIcon("zoom-in",""), tr("Increase Desktop Icon Sizes"), this, SIGNAL(IncreaseIconSize()) ); + menu->addAction( LXDG::findIcon("zoom-out",""), tr("Decrease Desktop Icon Sizes"), this, SIGNAL(DecreaseIconSize()) ); + menu->addSeparator(); menu->addAction( LXDG::findIcon("edit-delete",""), tr("Remove Item"), this, SLOT(slotRemovePlugin()) ); } diff --git a/lumina-desktop/desktop-plugins/LDPlugin.h b/lumina-desktop/desktop-plugins/LDPlugin.h index f9e5a12b..521a89f4 100644 --- a/lumina-desktop/desktop-plugins/LDPlugin.h +++ b/lumina-desktop/desktop-plugins/LDPlugin.h @@ -106,6 +106,8 @@ signals: void StartMoving(QString); //ID of plugin void StartResizing(QString); //ID of plugin void RemovePlugin(QString); //ID of plugin + void IncreaseIconSize(); // only used for desktop icons + void DecreaseIconSize(); // only used for desktop icons private slots: void slotStartMove(){ diff --git a/lumina-desktop/desktop-plugins/applauncher/AppLauncherPlugin.cpp b/lumina-desktop/desktop-plugins/applauncher/AppLauncherPlugin.cpp index cf7f84d4..f2fd2206 100644 --- a/lumina-desktop/desktop-plugins/applauncher/AppLauncherPlugin.cpp +++ b/lumina-desktop/desktop-plugins/applauncher/AppLauncherPlugin.cpp @@ -34,7 +34,7 @@ AppLauncherPlugin::AppLauncherPlugin(QWidget* parent, QString ID) : LDPlugin(par //QSize sz(qRound(1.1*icosize), icosize+qRound(2.7*button->fontMetrics().height()) ); //button->setFixedSize(sz); //make sure to adjust the button on first show. this->setInitialSize(120, 100); //give the container a bit of a buffer - QTimer::singleShot(100,this, SLOT(loadButton()) ); + QTimer::singleShot(200,this, SLOT(loadButton()) ); } void AppLauncherPlugin::Cleanup(){ @@ -89,6 +89,12 @@ void AppLauncherPlugin::loadButton(){ } //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->icon().actualSize(button->iconSize()) != button->iconSize()){ + QIcon ico = button->icon(); + ico.addPixmap( ico.pixmap(button->iconSize()).scaled(button->iconSize(), Qt::KeepAspectRatio, Qt::SmoothTransformation) ); + button->setIcon(ico); + } //int icosize = this->readSetting("iconsize",64).toInt(); //int bwid = qRound(1.1*icosize); //this->setFixedSize(bwid, icosize+qRound(2.5*button->fontMetrics().height()) ); //make sure to adjust the button on first show. diff --git a/lumina-desktop/desktop-plugins/applauncher/OutlineToolButton.h b/lumina-desktop/desktop-plugins/applauncher/OutlineToolButton.h index 7a0f28cf..7c8c012d 100644 --- a/lumina-desktop/desktop-plugins/applauncher/OutlineToolButton.h +++ b/lumina-desktop/desktop-plugins/applauncher/OutlineToolButton.h @@ -27,7 +27,6 @@ public: //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) - font.setWeight(70); //need a slightly heavier weight due to outlining later this->setFont(font); } ~OutlineToolButton(){} @@ -45,8 +44,10 @@ protected: QStylePainter p(this); QStyleOptionToolButton opt; initStyleOption(&opt); + opt.font = this->property("font").value(); //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.setWeight(65); //need a slightly heavier weight due to outlining later + 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 @@ -55,9 +56,12 @@ protected: 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, 80); } - else{outC.setHsl(textC.hue(), textC.hslSaturation(), 255, 80); } + if(textC.lightnessF() > 0.5){ outC.setHsl(textC.hue(), textC.hslSaturation(), 0, 110); } + else{outC.setHsl(textC.hue(), textC.hslSaturation(), 255, 110); } //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")/3.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 @@ -67,7 +71,7 @@ protected: path.setFillRule(Qt::WindingFill); //Now paint the text p.setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing); //need antialiasing for this to work well (sub-pixel painting) - p.strokePath(path, QPen(QBrush(outC),1.8, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin) ); //This will be the outline - 1pixel thick, semi-transparent + p.strokePath(path, QPen(QBrush(outC),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 } -- cgit