Changeset b43841d


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

Completely finish up the new Lumina desktop plugin framework. Now it works beautifully, with multiple instances of each plugin possible, and automatically tiled positions of new plugins.

Location:
lumina/lumina-desktop
Files:
6 edited

Legend:

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

    r05161ee rb43841d  
    8989// ===================== 
    9090void LDesktop::SettingsChanged(){ 
     91  if(changingsettings){ return; } //don't refresh for internal modifications to the file 
    9192  settings->sync(); //make sure to catch external settings changes 
    9293  QTimer::singleShot(1,this, SLOT(UpdateMenu()) ); 
     
    138139  QStringList plugins = settings->value(DPREFIX+"pluginlist", QStringList()).toStringList(); 
    139140  if(defaultdesktop && plugins.isEmpty()){ 
    140     //plugins << "sample"; 
    141   } 
     141    //plugins << "sample" << "sample" << "sample"; 
     142  } 
     143  bool changed=false; //in case the plugin list needs to be changed 
    142144  for(int i=0; i<plugins.length(); i++){ 
    143145    //See if this plugin is already there 
    144146    LDPlugin *plug = 0; 
    145147    for(int p=0; p<PLUGINS.length(); p++){ 
    146       if(PLUGINS[p]->type()==plugins[i]){ 
     148      if(PLUGINS[p]->ID()==plugins[i]){ 
    147149        plug = PLUGINS[p]; 
    148150        break; 
     
    151153    if(plug==0){ 
    152154      //New Plugin 
     155        //Make sure the plugin ID is unique 
     156        if(!plugins[i].contains("---") ){ 
     157          int num=1; 
     158          while( plugins.contains(plugins[i]+"---"+QString::number(desktopnumber)+"."+QString::number(num)) ){ 
     159            num++; 
     160          } 
     161          plugins[i] = plugins[i]+"---"+QString::number(desktopnumber)+"."+QString::number(num); 
     162          changed=true; 
     163        } 
     164      //Now create the plugin (will load existing settings if possible) 
    153165      qDebug() << " -- New Plugin:" << plugins[i]; 
    154       plug = NewDP::createPlugin(plugins[i], bgWindow, bgWindow->geometry()); 
     166      plug = NewDP::createPlugin(plugins[i], bgDesktop); 
    155167      if(plug != 0){  
    156         qDebug() << " -- Show Plugin"; 
     168        //qDebug() << " -- Show Plugin"; 
    157169        PLUGINS << plug; 
    158170        CreateDesktopPluginContainer(plug); 
     
    160172    } 
    161173  
     174  } 
     175  if(changed){ 
     176    //save the modified plugin list to file (so per-plugin settings are preserved) 
     177    changingsettings=true; //don't let the change cause a refresh 
     178    settings->setValue(DPREFIX+"pluginlist", plugins); 
     179    settings->sync(); 
     180    changingsettings=false; //finished changing setting 
    162181  } 
    163182} 
  • lumina/lumina-desktop/LDesktop.h

    r130bc0e rb43841d  
    5151        int desktopnumber; 
    5252        int xoffset; 
    53         bool defaultdesktop, desktoplocked; 
     53        bool defaultdesktop, desktoplocked, changingsettings; 
    5454        QList<LPanel*> PANELS; 
    5555        QMdiArea *bgDesktop; //desktop widget area 
  • lumina/lumina-desktop/desktop-plugins/LDPlugin.h

    r130bc0e rb43841d  
    2626         
    2727private: 
    28         QString plugintype; 
     28        QString PLUGID; 
    2929        QRect validRect; 
    3030         
     
    3232        QSettings *settings; 
    3333 
    34         LDPlugin(QWidget *parent = 0, QRect rect = QRect(), QString ptype="unknown") : QWidget(parent){ 
    35           plugintype=ptype; 
    36           validRect = rect; 
    37           settings = new QSettings("desktop-plugins",ptype); 
     34        LDPlugin(QWidget *parent = 0, QString id="unknown") : QWidget(parent){ 
     35          PLUGID=id; 
     36          settings = new QSettings("desktop-plugins",PLUGID); 
    3837        } 
    3938         
     
    4241        } 
    4342         
    44         QString type(){ 
    45           return plugintype; 
    46         } 
    47          
    48         void updateValidRect(QRect rect){ 
    49           validRect = rect; 
    50           QTimer::singleShot(0, this, SLOT(validateGeometry()) ); 
     43        QString ID(){ 
     44          return PLUGID; 
    5145        } 
    5246         
    5347public slots: 
    54         void validateGeometry(bool canmove = true){ 
    55           //This checks the current location of the widget against the valid area 
    56           qDebug() << "DP geom:" << this->rect().x() << this->rect().y() << this->rect().width() << this->rect().height(); 
    57           if(!validRect.contains(this->rect())){ 
    58             qDebug() << "Invalid Geometry:" << this->rect().x() << this->rect().y() << this->rect().width() << this->rect().height(); 
    59             qDebug() << " - Valid:" << validRect.x() << validRect.y() << validRect.width() << validRect.height(); 
    60             //Move to just within the valid region 
    61             if(canmove){ 
    62                      
    63             } 
    64           } 
    65         } 
    66          
    6748        virtual void LocaleChange(){ 
    6849          //This needs to be re-implemented in the subclassed plugin 
     
    7354            //This is where all the visuals are set if using Theme-dependant icons. 
    7455        } 
    75 /* 
    76 protected: 
    77         virtual void MoveEvent(QMoveEvent *event){ 
    78           //Save this location to the settings 
    79           qDebug() << "DP Move:" << event->pos().x() << event->pos().y(); 
    80           settings->setValue("location/x", event->pos().x()); 
    81           settings->setValue("location/y", event->pos().y()); 
    82         } 
    83         virtual void ResizeEvent(QResizeEvent *event){ 
    84           //Save this size info to the settings 
    85           qDebug() << "DP Resize:" << event->size().width() << event->size().height(); 
    86           settings->setValue("location/width", event->size().width()); 
    87           settings->setValue("location/height", event->size().height()); 
    88         } 
    89 */       
    9056}; 
    9157 
  • lumina/lumina-desktop/desktop-plugins/LDPluginContainer.h

    r59fa950 rb43841d  
    3333          else{ this->setWindowFlags(Qt::CustomizeWindowHint); } 
    3434          settings = plugin->settings; //save this pointer for access later 
     35          if(settings->allKeys().isEmpty()){ 
     36            //Brand new plugin - no location/size info saved yet 
     37            //save the initial size of the plugin - the initial location will be set automatically 
     38              settings->setValue("location/width", plugin->sizeHint().width()); 
     39              settings->setValue("location/height", plugin->sizeHint().height()); 
     40              settings->sync(); 
     41          } 
    3542          this->setContentsMargins(0,0,0,0); 
    3643          if(!locked){ 
    37             this->setWindowTitle(plugin->type()); 
     44            this->setWindowTitle( plugin->ID().replace("---"," - ") ); 
    3845            this->setWidget( new QWidget() ); 
    3946            //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;}"); 
     
    4855 
    4956        void loadInitialPosition(){ 
    50           QRect set(settings->value("location/x",0).toInt(), settings->value("location/y",0).toInt(), settings->value("location/width",this->widget()->sizeHint().width()).toInt(), settings->value("location/height",this->widget()->sizeHint().height()).toInt()); 
    51           qDebug() << "Initial Plugin Location:" << set.x() << set.y() << set.width() << set.height(); 
     57          QRect set(settings->value("location/x",-12345).toInt(), settings->value("location/y",-12345).toInt(), settings->value("location/width",this->widget()->sizeHint().width()).toInt(), settings->value("location/height",this->widget()->sizeHint().height()).toInt()); 
     58          //qDebug() << "Initial Plugin Location:" << set.x() << set.y() << set.width() << set.height(); 
    5259            if(set.height() < 10){ set.setHeight(10); } //to prevent foot-shooting 
    5360            if(set.width() < 10){ set.setWidth(10); } //to prevent foot-shooting 
    54             this->setGeometry(set); 
     61            if(set.x()!=-12345 && set.y()!=-12345){ 
     62              //custom location specified 
     63              this->setGeometry(set); 
     64            }else{ 
     65              this->resize(set.width(), set.height()); 
     66            } 
    5567          setup=false; //done with setup 
    5668        } 
  • lumina/lumina-desktop/desktop-plugins/NewDP.h

    r64bfe71 rb43841d  
    1919class NewDP{ 
    2020public: 
    21         static LDPlugin* createPlugin(QString plugin, QWidget* parent=0, QRect rect = QRect()){ 
     21        static LDPlugin* createPlugin(QString plugin, QWidget* parent=0){ 
    2222          LDPlugin *plug = 0; 
    23           if(plugin=="sample"){ 
    24             plug = new SamplePlugin(parent, rect); 
     23          if(plugin.section("---",0,0)=="sample"){ 
     24            plug = new SamplePlugin(parent, plugin); 
    2525          }else{ 
    2626            qWarning() << "Invalid Desktop Plugin:"<<plugin << " -- Ignored"; 
  • lumina/lumina-desktop/desktop-plugins/SamplePlugin.h

    r130bc0e rb43841d  
    1818        Q_OBJECT 
    1919public: 
    20         SamplePlugin(QWidget* parent, QRect rect) : LDPlugin(parent, rect, "sample"){ 
     20        SamplePlugin(QWidget* parent, QString ID) : LDPlugin(parent, ID){ 
    2121          this->setLayout( new QVBoxLayout()); 
     22            this->layout()->setContentsMargins(0,0,0,0); 
    2223          button = new QPushButton("sample"); 
    2324          this->layout()->addWidget(button); 
Note: See TracChangeset for help on using the changeset viewer.