LUserButtonPlugin::LUserButtonPlugin(QWidget *parent, QString id, bool horizontal) : LPPlugin(parent, id, horizontal){ button = new QToolButton(this); button->setAutoRaise(true); button->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); button->setPopupMode(QToolButton::DelayedPopup); //make sure it runs the update routine first connect(button, SIGNAL(clicked()), this, SLOT(openMenu())); this->layout()->setContentsMargins(0,0,0,0); this->layout()->addWidget(button); menu = new QMenu(this); menu->setContentsMargins(1,1,1,1); connect(menu, SIGNAL(aboutToHide()), this, SIGNAL(MenuClosed())); usermenu = new UserWidget(this); connect(usermenu, SIGNAL(CloseMenu()), this, SLOT(closeMenu()) ); mact = new QWidgetAction(this); mact->setDefaultWidget(usermenu); menu->addAction(mact); button->setMenu(menu); connect(menu, SIGNAL(aboutToHide()), this, SLOT(updateButtonVisuals()) ); //Setup the global shortcut handling for opening the start menu connect(QApplication::instance(), SIGNAL(StartButtonActivated()), this, SLOT(shortcutActivated()) ); LSession::handle()->registerStartButton(this->type()); QTimer::singleShot(0,this, SLOT(OrientationChange())); //Update icons/sizes }
LBattery::LBattery(QWidget *parent, QString id, bool horizontal) : LPPlugin(parent, id, horizontal){ iconOld = -1; //Setup the widget label = new QLabel(this); label->setScaledContents(true); //label->setAlignment(Qt::AlignCenter); this->layout()->addWidget(label); //Setup the timer timer = new QTimer(); timer->setInterval(5000); //update every 5 seconds connect(timer,SIGNAL(timeout()), this, SLOT(updateBattery()) ); timer->start(); QTimer::singleShot(0,this,SLOT(OrientationChange()) ); //update the sizing/icon }
AppLaunchButtonPlugin::AppLaunchButtonPlugin(QWidget *parent, QString id, bool horizontal) : LPPlugin(parent, id, horizontal) { button = new QToolButton(this); button->setAutoRaise(true); button->setToolButtonStyle(Qt::ToolButtonIconOnly); appfile = id.section("---",0,0).section("::",1,1); if(!QFile::exists(appfile)) { appfile.clear(); } connect(button, SIGNAL(clicked()), this, SLOT(AppClicked())); this->layout()->setContentsMargins(0,0,0,0); this->layout()->addWidget(button); QTimer::singleShot(0,this, SLOT(OrientationChange())); //Update icons/sizes }
LDeskBarPlugin::LDeskBarPlugin(QWidget *parent, QString id, bool horizontal) : LPPlugin(parent, id, horizontal){ this->layout()->setContentsMargins(0,0,0,0); this->setStyleSheet( "QToolButton::menu-indicator{ image: none; } QToolButton{ padding: 0px; }"); //initialize the desktop bar items initializeDesktop(); //setup the directory watcher QString fav = QString(getenv("XDG_CONFIG_HOME"))+"/lumina-desktop/favorites.list"; if(!QFile::exists(fav)){ QProcess::execute("touch \""+fav+"\""); } watcher = new QFileSystemWatcher(this); watcher->addPath( fav ); connect(watcher, SIGNAL(fileChanged(QString)), this, SLOT(filechanged(QString)) ); QTimer::singleShot(1,this, SLOT(updateFiles()) ); //make sure to load it the first time QTimer::singleShot(0,this, SLOT(OrientationChange()) ); //adjust sizes/layout connect(QApplication::instance(), SIGNAL(DesktopFilesChanged()), this, SLOT(updateFiles()) ); }
LStartButtonPlugin::LStartButtonPlugin(QWidget *parent, QString id, bool horizontal) : LPPlugin(parent, id, horizontal){ button = new QToolButton(this); button->setAutoRaise(true); button->setToolButtonStyle(Qt::ToolButtonIconOnly); button->setPopupMode(QToolButton::DelayedPopup); //make sure it runs the update routine first connect(button, SIGNAL(clicked()), this, SLOT(openMenu())); this->layout()->setContentsMargins(0,0,0,0); this->layout()->addWidget(button); menu = new QMenu(this); menu->setContentsMargins(1,1,1,1); startmenu = new StartMenu(this); connect(startmenu, SIGNAL(CloseMenu()), this, SLOT(closeMenu()) ); mact = new QWidgetAction(this); mact->setDefaultWidget(startmenu); menu->addAction(mact); button->setMenu(menu); connect(menu, SIGNAL(aboutToHide()), this, SLOT(updateButtonVisuals()) ); QTimer::singleShot(0,this, SLOT(OrientationChange())); //Update icons/sizes }
void LStartButtonPlugin::updateQuickLaunch(QStringList apps){ //First clear any obsolete apps QStringList old; qDebug() << "Update QuickLaunch Buttons"; for(int i=0; i<QUICKL.length(); i++){ if( !apps.contains(QUICKL[i]->whatsThis()) ){ //App was removed QUICKL.takeAt(i)->deleteLater(); i--; }else{ //App still listed - update the button old << QUICKL[i]->whatsThis(); //add the list of current buttons LFileInfo info(QUICKL[i]->whatsThis()); QUICKL[i]->setIcon( LXDG::findIcon(info.iconfile(),"unknown") ); if(info.isDesktopFile()){ QUICKL[i]->setToolTip( info.XDG()->name ); } else{ QUICKL[i]->setToolTip( info.fileName() ); } } } //Now go through and create any new buttons for(int i=0; i<apps.length(); i++){ if( !old.contains(apps[i]) ){ //New App LQuickLaunchButton *tmp = new LQuickLaunchButton(apps[i], this); QUICKL << tmp; LFileInfo info(apps[i]); tmp->setIcon( LXDG::findIcon( info.iconfile() ) ); if(info.isDesktopFile()){ tmp->setToolTip( info.XDG()->name ); } else{ tmp->setToolTip( info.fileName() ); } //Now add the button to the layout and connect the signal/slots this->layout()->insertWidget(i+1,tmp); //"button" is always in slot 0 connect(tmp, SIGNAL(Launch(QString)), this, SLOT(LaunchQuick(QString)) ); connect(tmp, SIGNAL(Remove(QString)), this, SLOT(RemoveQuick(QString)) ); } } qDebug() << " - Done updateing QuickLaunch Buttons"; QTimer::singleShot(0,this, SLOT(OrientationChange())); //Update icons/sizes }
LClock::LClock(QWidget *parent, QString id, bool horizontal) : LPPlugin(parent, id, horizontal){ button = new QToolButton(this); //RotateToolButton(this); button->setAutoRaise(true); button->setToolButtonStyle(Qt::ToolButtonTextOnly); button->setStyleSheet("font-weight: bold;"); button->setPopupMode(QToolButton::DelayedPopup); //make sure it runs the update routine first button->setMenu(new QMenu()); //button->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred); //this->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred); connect(button, SIGNAL(clicked()), this, SLOT(openMenu())); connect(button->menu(), SIGNAL(aboutToHide()), this, SIGNAL(MenuClosed())); calendar = new QCalendarWidget(this); calAct = new QWidgetAction(this); calAct->setDefaultWidget(calendar); TZMenu = new QMenu(this); connect(TZMenu, SIGNAL(triggered(QAction*)), this, SLOT(ChangeTZ(QAction*)) ); //Now assemble the menu button->menu()->addAction(calAct); button->menu()->addMenu(TZMenu); this->layout()->setContentsMargins(0,0,0,0); //reserve some space on left/right this->layout()->addWidget(button); //Setup the timer timer = new QTimer(); //Load all the initial settings updateFormats(); LocaleChange(); ThemeChange(); OrientationChange(); //Now connect/start the timer connect(timer,SIGNAL(timeout()), this, SLOT(updateTime()) ); connect(QApplication::instance(), SIGNAL(SessionConfigChanged()), this, SLOT(updateFormats()) ); timer->start(); }
LStartButtonPlugin::LStartButtonPlugin(QWidget *parent, QString id, bool horizontal) : LPPlugin(parent, id, horizontal){ button = new QToolButton(this); button->setAutoRaise(true); button->setToolButtonStyle(Qt::ToolButtonIconOnly); button->setPopupMode(QToolButton::DelayedPopup); //make sure it runs the update routine first connect(button, SIGNAL(clicked()), this, SLOT(openMenu())); this->layout()->setContentsMargins(0,0,0,0); this->layout()->addWidget(button); menu = new ResizeMenu(this); menu->setContentsMargins(1,1,1,1); connect(menu, SIGNAL(aboutToHide()), this, SIGNAL(MenuClosed())); connect(menu, SIGNAL(MenuResized(QSize)), this, SLOT(SaveMenuSize(QSize)) ); startmenu = new StartMenu(this); connect(startmenu, SIGNAL(CloseMenu()), this, SLOT(closeMenu()) ); connect(startmenu, SIGNAL(UpdateQuickLaunch(QStringList)), this, SLOT(updateQuickLaunch(QStringList))); menu->setContents(startmenu); QSize saved = LSession::handle()->DesktopPluginSettings()->value("panelPlugs/"+this->type()+"/MenuSize", QSize(0,0)).toSize(); if(!saved.isNull()){ startmenu->setFixedSize(saved); } //re-load the previously saved value button->setMenu(menu); connect(menu, SIGNAL(aboutToHide()), this, SLOT(updateButtonVisuals()) ); QTimer::singleShot(0,this, SLOT(OrientationChange())); //Update icons/sizes QTimer::singleShot(0, startmenu, SLOT(ReLoadQuickLaunch()) ); }
//=========== // PUBLIC SLOTS //=========== void LPanel::UpdatePanel(bool geomonly){ //Create/Update the panel as designated in the Settings file settings->sync(); //make sure to catch external settings changes //First set the geometry of the panel and send the EWMH message to reserve that space if(DEBUG){ qDebug() << "Update Panel: Geometry only=" << geomonly << "Screen Size:" << LSession::handle()->screenGeom(screennum); } hidden = settings->value(PPREFIX+"hidepanel",false).toBool(); QString loc = settings->value(PPREFIX+"location","").toString().toLower(); if(loc.isEmpty() && defaultpanel){ loc="top"; } if(loc=="top" || loc=="bottom"){ horizontal=true; layout->setAlignment(Qt::AlignLeft); layout->setDirection(QBoxLayout::LeftToRight); }else{ horizontal=false; layout->setAlignment(Qt::AlignTop); layout->setDirection(QBoxLayout::TopToBottom); } int ht = settings->value(PPREFIX+"height", 30).toInt(); //this is technically the distance into the screen from the edge if(ht<=1){ ht = 30; } //some kind of error in the saved height - use the default value int hidesize = qRound(ht*0.01); //use 1% of the panel size if(hidesize<2){ hidesize=2; } //minimum of 2 pixels (need space for the mouse to go over it) if(hidden){ viswidth = hidesize; } else{ viswidth = ht; } if(DEBUG){ qDebug() << "Hidden Panel size:" << hidesize << "pixels"; } //qDebug() << " - set Geometry"; int xwid = LSession::handle()->screenGeom(screennum).width(); int xhi = LSession::handle()->screenGeom(screennum).height(); int xloc = LSession::handle()->screenGeom(screennum).x(); double panelPercent = settings->value(PPREFIX+"lengthPercent",100).toInt(); if(panelPercent<1 || panelPercent>100){ panelPercent = 100; } panelPercent = panelPercent/100.0; QString panelPinLoc = settings->value(PPREFIX+"pinLocation","center").toString().toLower(); //[left/right/center] possible values (assume center otherwise) if(DEBUG){ qDebug() << " - Panel settings:" << QString::number(panelPercent)+QString("%") << panelPinLoc << loc; } //xloc=xoffset; if(loc=="top"){ //top of screen QSize sz = QSize(xwid*panelPercent, ht); if(panelPinLoc=="left"){} // no change to xloc else if(panelPinLoc=="right"){ xloc = xloc+xwid-sz.width(); } else{ xloc = xloc+((xwid-sz.width())/2) ; } //centered //qDebug() << " - Panel Sizing:" << xloc << sz; this->setMinimumSize(sz); this->setMaximumSize(sz); this->setGeometry(xloc,0,sz.width(), sz.height()); //qDebug() << " - Reserve Panel Localation"; if(!hidden){ LSession::handle()->XCB->ReserveLocation(this->winId(), this->geometry(), "top"); } else{ LSession::handle()->XCB->ReserveLocation(this->winId(), QRect(xloc, 0, this->width(), hidesize), "top"); hidepoint = QPoint(xloc, hidesize-ht); showpoint = QPoint(xloc, 0); this->move(hidepoint); //Could bleed over onto the screen above } }else if(loc=="bottom"){ //bottom of screen QSize sz = QSize(xwid*panelPercent, ht); if(panelPinLoc=="left"){} // no change to xloc else if(panelPinLoc=="right"){ xloc = xloc+xwid-sz.width(); } else{ xloc = xloc+((xwid-sz.width())/2) ; } //centered this->setMinimumSize(sz); this->setMaximumSize(sz); this->setGeometry(xloc,xhi-ht,sz.width(), ht ); if(!hidden){ LSession::handle()->XCB->ReserveLocation(this->winId(), this->geometry(), "bottom"); } else{ LSession::handle()->XCB->ReserveLocation(this->winId(), QRect(xloc, xhi-hidesize, this->width(), hidesize), "bottom"); hidepoint = QPoint(xloc, xhi-hidesize); showpoint = QPoint(xloc, xhi-ht); this->move(hidepoint); //Could bleed over onto the screen below } }else if(loc=="left"){ //left side of screen QSize sz = QSize(ht, xhi*panelPercent); int yloc = 0; if(panelPinLoc=="left"){} //this is actually the top (left of center in length dimension) else if(panelPinLoc=="right"){ yloc = yloc+xhi-sz.height(); } else{ yloc = yloc+((xhi-sz.height())/2) ; } //centered this->setMinimumSize(sz); this->setMaximumSize(sz); this->setGeometry(xloc,yloc, ht, sz.height()); if(!hidden){ LSession::handle()->XCB->ReserveLocation(this->winId(), this->geometry(), "left"); } else{ LSession::handle()->XCB->ReserveLocation(this->winId(), QRect(xloc, yloc, hidesize, sz.height()), "left"); hidepoint = QPoint(xloc-ht+hidesize, yloc); showpoint = QPoint(xloc, yloc); this->move(hidepoint); //Could bleed over onto the screen left } }else{ //right side of screen QSize sz = QSize(ht, xhi*panelPercent); int yloc = 0; if(panelPinLoc=="left"){} //this is actually the top (left of center in length dimension) else if(panelPinLoc=="right"){ yloc = yloc+xhi-sz.height(); } else{ yloc = yloc+((xhi-sz.height())/2) ; } //centered this->setMinimumSize(sz); this->setMaximumSize(sz); this->setGeometry(xloc+xwid-ht,yloc,ht, sz.height()); if(!hidden){ LSession::handle()->XCB->ReserveLocation(this->winId(), this->geometry(), "right"); } else{ LSession::handle()->XCB->ReserveLocation(this->winId(), QRect(xloc+xwid-hidesize, yloc, hidesize, sz.height()), "right"); hidepoint = QPoint(xloc+xwid-hidesize, yloc); showpoint = QPoint(xloc+xwid-ht, yloc); this->move(hidepoint); //Could bleed over onto the screen right } } //With QT5, we need to make sure to reset window properties on occasion //LSession::handle()->XCB->SetDisableWMActions(this->winId()); //ensure no WM actions //LSession::handle()->XCB->SetAsSticky(this->winId()); if(DEBUG){ qDebug() << " - Done with panel geometry"; } if(geomonly){ return; } //Now update the appearance of the toolbar if(settings->value(PPREFIX+"customcolor", false).toBool()){ QString color = settings->value(PPREFIX+"color", "rgba(255,255,255,160)").toString(); QString style = "QWidget#LuminaPanelColor{ background: %1; border-radius: 3px; border: 1px solid %1; }"; style = style.arg(color); panelArea->setStyleSheet(style); }else{ panelArea->setStyleSheet(""); //clear it and use the one from the theme } //Then go through the plugins and create them as necessary QStringList plugins = settings->value(PPREFIX+"pluginlist", QStringList()).toStringList(); /*if(defaultpanel && plugins.isEmpty()){ plugins << "userbutton" << "taskmanager" << "spacer" << "systemtray" << "clock" << "systemdashboard"; }*/ if(DEBUG){ qDebug() << " - Initialize Plugins: " << plugins; } for(int i=0; i<plugins.length(); i++){ //Ensure this plugin has a unique ID (NOTE: this numbering does not persist between sessions) if(!plugins[i].contains("---")){ int num=1; while( plugins.contains(plugins[i]+"---"+QString::number(screennum)+"."+QString::number(this->number())+"."+QString::number(num)) ){ num++; } plugins[i] = plugins[i]+"---"+QString::number(screennum)+"."+QString::number(this->number())+"."+QString::number(num); //qDebug() << "Adjust Plugin ID:" << plugins[i]; } //See if this plugin is already there or in a different spot bool found = false; for(int p=0; p<PLUGINS.length(); p++){ if(PLUGINS[p]->type()==plugins[i]){ found = true; //already exists //Make sure the plugin layout has the correct orientation if(horizontal){PLUGINS[p]->layout()->setDirection(QBoxLayout::LeftToRight); } else{ PLUGINS[p]->layout()->setDirection(QBoxLayout::TopToBottom); } QTimer::singleShot(0,PLUGINS[p], SLOT( OrientationChange() ) ); //Now check the location of the plugin in the panel if(p!=i){ //wrong place in the panel layout->takeAt(p); //remove the item from the current location layout->insertWidget(i, PLUGINS[p]); //add the item into the correct location PLUGINS.move(p,i); //move the identifier in the list to match } break; } } if(!found){ //New Plugin if(DEBUG){ qDebug() << " -- New Plugin:" << plugins[i] << i; } LPPlugin *plug = NewPP::createPlugin(plugins[i], panelArea, horizontal); if(plug != 0){ PLUGINS.insert(i, plug); layout->insertWidget(i, PLUGINS[i]); connect(plug, SIGNAL(MenuClosed()), this, SLOT(checkPanelFocus())); }else{ //invalid plugin type plugins.removeAt(i); //remove this invalid plugin from the list i--; //make sure we don't miss the next item with the re-order } } LSession::processEvents(); } //Now remove any extra plugins from the end //qDebug() << "plugins:" << plugins; //qDebug() << "PLUGINS length:" << PLUGINS.length(); for(int i=0; i<PLUGINS.length(); i++){ if(plugins.contains(PLUGINS[i]->type())){ continue; } //good plugin - skip it if(DEBUG){ qDebug() << " -- Remove Plugin: " << PLUGINS[i]->type(); } //If this is the system tray - stop it first if( PLUGINS[i]->type().startsWith("systemtray---") ){ static_cast<LSysTray*>(PLUGINS[i])->stop(); } layout->takeAt(i); //remove from the layout delete PLUGINS.takeAt(i); //delete the actual widget LSession::processEvents(); i--; //need to back up one space to not miss another plugin } this->update(); this->show(); //make sure the panel is visible now if(hidden){ this->move(hidepoint); } //Now go through and send the orientation update signal to each plugin for(int i=0; i<PLUGINS.length(); i++){ QTimer::singleShot(0,PLUGINS[i], SLOT(OrientationChange())); } LSession::processEvents(); }