mirror of
				https://github.com/arcan1s/awesome-widgets.git
				synced 2025-11-04 06:43:41 +00:00 
			
		
		
		
	implement contextual menu to listWidgets
This commit is contained in:
		@ -7,7 +7,7 @@
 | 
			
		||||
    <x>0</x>
 | 
			
		||||
    <y>0</y>
 | 
			
		||||
    <width>700</width>
 | 
			
		||||
    <height>592</height>
 | 
			
		||||
    <height>590</height>
 | 
			
		||||
   </rect>
 | 
			
		||||
  </property>
 | 
			
		||||
  <property name="sizePolicy">
 | 
			
		||||
@ -41,9 +41,9 @@
 | 
			
		||||
      <property name="geometry">
 | 
			
		||||
       <rect>
 | 
			
		||||
        <x>0</x>
 | 
			
		||||
        <y>-225</y>
 | 
			
		||||
        <width>677</width>
 | 
			
		||||
        <height>801</height>
 | 
			
		||||
        <y>-239</y>
 | 
			
		||||
        <width>675</width>
 | 
			
		||||
        <height>813</height>
 | 
			
		||||
       </rect>
 | 
			
		||||
      </property>
 | 
			
		||||
      <layout class="QVBoxLayout" name="verticalLayout_8">
 | 
			
		||||
@ -469,7 +469,11 @@ $m - uptime minutes without zero</string>
 | 
			
		||||
          </layout>
 | 
			
		||||
         </item>
 | 
			
		||||
         <item>
 | 
			
		||||
          <widget class="QListWidget" name="listWidget_bars"/>
 | 
			
		||||
          <widget class="QListWidget" name="listWidget_bars">
 | 
			
		||||
           <property name="contextMenuPolicy">
 | 
			
		||||
            <enum>Qt::CustomContextMenu</enum>
 | 
			
		||||
           </property>
 | 
			
		||||
          </widget>
 | 
			
		||||
         </item>
 | 
			
		||||
        </layout>
 | 
			
		||||
       </item>
 | 
			
		||||
 | 
			
		||||
@ -82,6 +82,8 @@ private slots:
 | 
			
		||||
    void addBar();
 | 
			
		||||
    void addCustomScript();
 | 
			
		||||
    void addNewPkgCommand(QTableWidgetItem *item);
 | 
			
		||||
    void contextMenuBars(const QPoint pos);
 | 
			
		||||
    void contextMenuCustomCommand(const QPoint pos);
 | 
			
		||||
    void contextMenuPkgCommand(const QPoint pos);
 | 
			
		||||
    void editBar(QListWidgetItem *item);
 | 
			
		||||
    void editCustomCommand(QListWidgetItem *item);
 | 
			
		||||
 | 
			
		||||
@ -451,8 +451,12 @@ void AwesomeWidget::createConfigurationInterface(KConfigDialog *parent)
 | 
			
		||||
            this, SLOT(editTempItem(QListWidgetItem *)));
 | 
			
		||||
    connect(uiAdvancedConfig.listWidget_bars, SIGNAL(itemActivated(QListWidgetItem *)),
 | 
			
		||||
            this, SLOT(editBar(QListWidgetItem *)));
 | 
			
		||||
    connect(uiAdvancedConfig.listWidget_bars, SIGNAL(customContextMenuRequested(QPoint)),
 | 
			
		||||
            this, SLOT(contextMenuBars(QPoint)));
 | 
			
		||||
    connect(uiDEConfig.listWidget_custom, SIGNAL(itemActivated(QListWidgetItem *)),
 | 
			
		||||
            this, SLOT(editCustomCommand(QListWidgetItem *)));
 | 
			
		||||
    connect(uiDEConfig.listWidget_custom, SIGNAL(customContextMenuRequested(QPoint)),
 | 
			
		||||
            this, SLOT(contextMenuCustomCommand(QPoint)));
 | 
			
		||||
    connect(uiDEConfig.tableWidget_pkgCommand, SIGNAL(itemChanged(QTableWidgetItem *)),
 | 
			
		||||
            this, SLOT(addNewPkgCommand(QTableWidgetItem *)));
 | 
			
		||||
    connect(uiDEConfig.tableWidget_pkgCommand, SIGNAL(customContextMenuRequested(QPoint)),
 | 
			
		||||
@ -763,6 +767,50 @@ void AwesomeWidget::addNewPkgCommand(QTableWidgetItem *item)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void AwesomeWidget::contextMenuBars(const QPoint pos)
 | 
			
		||||
{
 | 
			
		||||
    if (debug) qDebug() << PDEBUG;
 | 
			
		||||
    if (uiAdvancedConfig.listWidget_bars->currentItem() == 0) return;
 | 
			
		||||
 | 
			
		||||
    QMenu menu(uiAdvancedConfig.listWidget_bars);
 | 
			
		||||
    QAction *edit = menu.addAction(QIcon::fromTheme("document-edit"), i18n("Edit"));
 | 
			
		||||
    QAction *remove = menu.addAction(QIcon::fromTheme("edit-delete"), i18n("Remove"));
 | 
			
		||||
    QAction *action = menu.exec(uiAdvancedConfig.listWidget_bars->viewport()->mapToGlobal(pos));
 | 
			
		||||
    if (action == edit)
 | 
			
		||||
        editBar(uiAdvancedConfig.listWidget_bars->currentItem());
 | 
			
		||||
    else if (action == remove)
 | 
			
		||||
        for (int i=0; i<graphicalItems.count(); i++) {
 | 
			
		||||
            if (graphicalItems[i]->getFileName() != uiAdvancedConfig.listWidget_bars->currentItem()->text())
 | 
			
		||||
                continue;
 | 
			
		||||
            graphicalItems[i]->tryDelete();
 | 
			
		||||
            graphicalItems.takeAt(i);
 | 
			
		||||
            uiAdvancedConfig.listWidget_bars->takeItem(uiAdvancedConfig.listWidget_bars->currentRow());
 | 
			
		||||
            break;
 | 
			
		||||
        }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void AwesomeWidget::contextMenuCustomCommand(const QPoint pos)
 | 
			
		||||
{
 | 
			
		||||
    if (debug) qDebug() << PDEBUG;
 | 
			
		||||
    if (uiDEConfig.listWidget_custom->currentItem() == 0) return;
 | 
			
		||||
 | 
			
		||||
    QMenu menu(uiDEConfig.listWidget_custom);
 | 
			
		||||
    QAction *edit = menu.addAction(QIcon::fromTheme("document-edit"), i18n("Edit"));
 | 
			
		||||
    QAction *remove = menu.addAction(QIcon::fromTheme("edit-delete"), i18n("Remove"));
 | 
			
		||||
    QAction *action = menu.exec(uiDEConfig.listWidget_custom->viewport()->mapToGlobal(pos));
 | 
			
		||||
    if (action == edit)
 | 
			
		||||
        editCustomCommand(uiDEConfig.listWidget_custom->currentItem());
 | 
			
		||||
    else if (action == remove) {
 | 
			
		||||
        QStringList dirs = KGlobal::dirs()->findDirs("data", "plasma_engine_extsysmon/scripts");
 | 
			
		||||
        ExtScript *script = new ExtScript(0, uiDEConfig.listWidget_custom->currentItem()->text(), dirs, debug);
 | 
			
		||||
        script->tryDelete();
 | 
			
		||||
        delete script;
 | 
			
		||||
        uiDEConfig.listWidget_custom->takeItem(uiDEConfig.listWidget_custom->currentRow());
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void AwesomeWidget::contextMenuPkgCommand(const QPoint pos)
 | 
			
		||||
{
 | 
			
		||||
    if (debug) qDebug() << PDEBUG;
 | 
			
		||||
 | 
			
		||||
@ -7,7 +7,7 @@
 | 
			
		||||
    <x>0</x>
 | 
			
		||||
    <y>0</y>
 | 
			
		||||
    <width>700</width>
 | 
			
		||||
    <height>584</height>
 | 
			
		||||
    <height>582</height>
 | 
			
		||||
   </rect>
 | 
			
		||||
  </property>
 | 
			
		||||
  <property name="sizePolicy">
 | 
			
		||||
@ -43,7 +43,7 @@
 | 
			
		||||
        <x>0</x>
 | 
			
		||||
        <y>0</y>
 | 
			
		||||
        <width>684</width>
 | 
			
		||||
        <height>568</height>
 | 
			
		||||
        <height>566</height>
 | 
			
		||||
       </rect>
 | 
			
		||||
      </property>
 | 
			
		||||
      <layout class="QGridLayout" name="gridLayout">
 | 
			
		||||
@ -507,7 +507,11 @@ del - remove item</string>
 | 
			
		||||
          </layout>
 | 
			
		||||
         </item>
 | 
			
		||||
         <item>
 | 
			
		||||
          <widget class="QListWidget" name="listWidget_custom"/>
 | 
			
		||||
          <widget class="QListWidget" name="listWidget_custom">
 | 
			
		||||
           <property name="contextMenuPolicy">
 | 
			
		||||
            <enum>Qt::CustomContextMenu</enum>
 | 
			
		||||
           </property>
 | 
			
		||||
          </widget>
 | 
			
		||||
         </item>
 | 
			
		||||
        </layout>
 | 
			
		||||
       </item>
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user