Changeset b74ce79


Ignore:
Timestamp:
07/10/14 09:35:46 (13 months ago)
Author:
Ken Moore <ken@…>
Branches:
master, enter/10, releng/10.0.3, releng/10.1, releng/10.1.1, releng/10.1.2
Children:
a65200d
Parents:
162c88d
Message:

Completely finish up the last items for the desktop plugin system.
1) Now the user can maximize/restore a plugin when in edit mode
2) Now the user can remove a plugin when in edit mode
3) Now the user can organize all the plugins on an intelligent grid (should be between 10-20 grid points on all screens), with no empty space

Location:
lumina/lumina-desktop
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • lumina/lumina-desktop/LDesktop.cpp

    rb43841d rb74ce79  
    11//=========================================== 
    22//  Lumina-DE source code 
    3 //  Copyright (c) 2012, Ken Moore 
     3//  Copyright (c) 2012-2014, Ken Moore 
    44//  Available under the 3-clause BSD license 
    55//  See the LICENSE file for full details 
     
    8080  LDPluginContainer *win = new LDPluginContainer(plug, desktoplocked); 
    8181  if(desktoplocked){ bgDesktop->addSubWindow(win, Qt::FramelessWindowHint); } 
    82   else{ bgDesktop->addSubWindow(win, Qt::CustomizeWindowHint); } 
     82  else{ bgDesktop->addSubWindow(win, Qt::CustomizeWindowHint | Qt::WindowMaximizeButtonHint | Qt::WindowCloseButtonHint); } 
    8383  win->loadInitialPosition(); 
    8484  win->show(); 
     85  win->update(); 
     86  connect(win, SIGNAL(PluginRemoved(QString)), this, SLOT(DesktopPluginRemoved(QString)) ); 
    8587} 
    8688 
     
    130132  //Now add the system quit options 
    131133  deskMenu->addSeparator(); 
    132   if(!desktoplocked){ deskMenu->addAction(LXDG::findIcon("document-encrypt",""),tr("Lock Desktop"), this, SLOT(ToggleDesktopLock()) ); } 
    133   else{ deskMenu->addAction(LXDG::findIcon("document-decrypt",""),tr("Unlock Desktop"), this, SLOT(ToggleDesktopLock()) ); } 
     134  if(!desktoplocked){  
     135    deskMenu->addAction(LXDG::findIcon("document-encrypt",""),tr("Lock Desktop"), this, SLOT(ToggleDesktopLock()) ); 
     136    deskMenu->addAction(LXDG::findIcon("snap-orthogonal",""),tr("Snap Plugins to Grid"), this, SLOT(AlignDesktopPlugins()) ); 
     137  }else{ deskMenu->addAction(LXDG::findIcon("document-decrypt",""),tr("Unlock Desktop"), this, SLOT(ToggleDesktopLock()) ); } 
     138  deskMenu->addSeparator(); 
    134139  deskMenu->addAction(LXDG::findIcon("system-log-out",""), tr("Log Out"), this, SLOT(SystemLogout()) ); 
    135140} 
     
    187192  QList<QMdiSubWindow*> wins = bgDesktop->subWindowList(); 
    188193  for(int i=0; i<wins.length(); i++){ 
     194    wins[i]->setWhatsThis(""); //clear this so it knows it is being temporarily removed 
    189195    bgDesktop->removeSubWindow(wins[i]->widget()); //unhook plugin from container 
    190196    bgDesktop->removeSubWindow(wins[i]); //remove container from screen 
     
    195201    CreateDesktopPluginContainer(PLUGINS[i]); 
    196202  } 
     203  bgDesktop->update(); //refresh visuals 
    197204  UpdateMenu(false);  
     205} 
     206 
     207void LDesktop::AlignDesktopPlugins(){ 
     208  QList<QMdiSubWindow*> wins = bgDesktop->subWindowList(); 
     209  QSize fit = bgDesktop->size(); 
     210  //Auto-determine the best grid sizing 
     211    // It will try to exactly fit the desktop plugin area, with at least 10-20 grid points 
     212  int xgrid, ygrid; 
     213        xgrid = ygrid = 20; 
     214        while(fit.width()%xgrid != 0){ xgrid = xgrid-1; } 
     215        while(fit.height()%ygrid != 0){ ygrid = ygrid-1; } 
     216  //qDebug() << "Grid:" << xgrid << ygrid << fit.width() << fit.height(); 
     217  //Make sure there are at least 10 points. It will not fit the area exactly, but should be very close 
     218  while(xgrid < 10){ xgrid = xgrid*2; } 
     219  while(ygrid < 10){ ygrid = ygrid*2; } 
     220  //qDebug() << "Grid (adjusted):" << xgrid << ygrid; 
     221  xgrid = int(fit.width()/xgrid); //now get the exact pixel size of the grid 
     222  ygrid = int(fit.height()/ygrid); //now get the exact pixel size of the grid 
     223  //qDebug() << "Grid (pixel):" << xgrid << ygrid; 
     224  //qDebug() << "  X-Grid:" << xgrid << "("+QString::number(fit.width()/xgrid)+" points)"; 
     225  //qDebug() << "  Y-Grid:" << ygrid << "("+QString::number(fit.height()/ygrid)+" points)"; 
     226  for(int i=0; i<wins.length(); i++){ 
     227    //align the plugin on a grid point (that is not right/bottom edge) 
     228    QRect geom = wins[i]->geometry(); 
     229        int x, y; 
     230        if(geom.x()<0){ x=0; } 
     231        else{ x = qRound(geom.x()/float(xgrid)) * xgrid; } 
     232        if(x>= fit.width()){ x = fit.width()-xgrid; geom.setWidth(xgrid); } 
     233        if(geom.y()<0){ y=0; } 
     234        else{ y = qRound(geom.y()/float(ygrid)) * ygrid; } 
     235        if(y>= fit.height()){ y = fit.height()-ygrid; geom.setHeight(ygrid); } 
     236        geom.moveTo(x,y); 
     237    //Now adjust the size to also be the appropriate grid multiple 
     238        geom.setWidth( qRound(geom.width()/float(xgrid))*xgrid ); 
     239        geom.setHeight( qRound(geom.height()/float(ygrid))*ygrid ); 
     240         
     241    //Now check for edge spillover and adjust accordingly 
     242        int diff = (geom.x()+geom.width()) - bgDesktop->size().width(); 
     243        if( diff > 0 ){ geom.moveTo( geom.x() - diff, geom.y() ); } 
     244        else if( diff > -11 ){ geom.setWidth( geom.width()-diff ); } 
     245        diff = (geom.y()+geom.height()) - bgDesktop->size().height(); 
     246        if( diff > 0 ){ geom.moveTo( geom.x(), geom.y() - diff ); } 
     247        else if( diff > -11 ){ geom.setHeight( geom.height()-diff ); } 
     248    //Now move the plugin 
     249        wins[i]->setGeometry(geom); 
     250  } 
     251} 
     252 
     253void LDesktop::DesktopPluginRemoved(QString ID){ 
     254  //Close down that plugin instance 
     255  for(int i=0; i<PLUGINS.length(); i++){ 
     256    if(PLUGINS[i]->ID() == ID){ 
     257      delete PLUGINS.takeAt(i); 
     258      break; 
     259    } 
     260  } 
     261  //Now remove that plugin from the internal list 
     262  QStringList plugins = settings->value(DPREFIX+"pluginlist",QStringList()).toStringList(); 
     263  plugins.removeAll(ID); 
     264  changingsettings=true; //don't let the change cause a refresh 
     265    settings->setValue(DPREFIX+"pluginlist", plugins); 
     266    settings->sync(); 
     267  changingsettings=false; //finished changing setting 
    198268} 
    199269 
  • lumina/lumina-desktop/LDesktop.h

    rb43841d rb74ce79  
    7373        } 
    7474         
     75        //Desktop plugin system functions 
    7576        void UpdateDesktop(); 
    7677        void ToggleDesktopLock(); 
     78        void AlignDesktopPlugins(); 
     79        void DesktopPluginRemoved(QString); 
    7780         
    7881        void UpdatePanels(); 
    7982         
    80         void UpdateDesktopPluginArea(); 
     83        void UpdateDesktopPluginArea(); //make sure the area is not underneath any panels 
    8184 
    8285        void UpdateBackground(); 
  • lumina/lumina-desktop/desktop-plugins/LDPlugin.h

    rb43841d rb74ce79  
    99//    visibility and usage within the desktop window 
    1010//=========================================== 
     11//  WARNING: Do *not* setup a custom context menu for plugins! 
     12//     This can prevent access to the general desktop context menu if 
     13//     the plugin was maximized to fill the desktop area! 
     14//=========================================== 
    1115#ifndef _LUMINA_DESKTOP_DESKTOP_PLUGIN_H 
    1216#define _LUMINA_DESKTOP_DESKTOP_PLUGIN_H 
    1317 
    1418#include <QObject> 
    15 #include <QMdiSubWindow> 
     19#include <QWidget> 
    1620#include <QString> 
    17 #include <QRect> 
    1821#include <QDebug> 
    1922#include <QSettings> 
    20 #include <QTimer> 
    2123#include <QMoveEvent> 
    2224#include <QResizeEvent> 
     
    2729private: 
    2830        QString PLUGID; 
    29         QRect validRect; 
    3031         
    3132public: 
  • lumina/lumina-desktop/desktop-plugins/LDPluginContainer.h

    rb43841d rb74ce79  
    3030          locked = islocked; 
    3131          setup=true; 
     32          this->setWhatsThis(plugin->ID()); 
    3233          if(locked){ this->setWindowFlags(Qt::FramelessWindowHint); } 
    33           else{ this->setWindowFlags(Qt::CustomizeWindowHint); } 
     34          else{ this->setWindowFlags(Qt::CustomizeWindowHint | Qt::WindowMaximizeButtonHint | Qt::WindowCloseButtonHint); } 
    3435          settings = plugin->settings; //save this pointer for access later 
    3536          if(settings->allKeys().isEmpty()){ 
     
    4647            //this->setStyleSheet("QMdiSubWindow{ padding: 0px; background: lightgrey; border: 2px solid grey; border-radius: 1px;} QMdiSubWindow::title{ background-color: lightgrey; height: 10px;  border: none; font: bold 8;}"); 
    4748          }else{ 
    48             this->setStyleSheet("LDPluginContainer{ padding: 0px; background: transparent; border: none;}"); 
     49            this->setStyleSheet("LDPluginContainer{ background: transparent; border: none;}"); 
    4950            this->setWidget(plugin); 
    5051          } 
     
    6768          setup=false; //done with setup 
    6869        } 
     70 
     71signals: 
     72        void PluginRemoved(QString); 
    6973         
    7074protected: 
     
    7781            settings->sync(); 
    7882          } 
    79           event->ignore(); 
    8083        } 
     84         
    8185        void resizeEvent(QResizeEvent *event){ 
    8286          //Save this size info to the settings 
     
    8791            settings->sync(); 
    8892          } 
    89           event->ignore(); 
     93        } 
     94         
     95        void closeEvent(QCloseEvent *event){ 
     96          if( !this->whatsThis().isEmpty() ){ 
     97            //Plugin removed by the user - delete the settings file 
     98            QFile::remove( settings->fileName() ); 
     99            emit PluginRemoved( this->whatsThis() ); 
     100          } 
     101          event->accept(); //continue closing the widget 
    90102        } 
    91103         
Note: See TracChangeset for help on using the changeset viewer.