[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: KDE/kdebase/workspace/klipper
From: Dmitry Suzdalev <dimsuz () gmail ! com>
Date: 2009-03-31 12:15:34
Message-ID: 1238501734.905595.15467.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 947291 by dimsuz:
Okay, now I think that action edit dialog is mostly working.
Few tweaks remain - like useful pop-up on double click etc, minor things.
Yay! :)
M +81 -2 editactiondialog.cpp
M +7 -0 editactiondialog.h
M +1 -1 editactiondialog.ui
M +3 -3 urlgrabber.h
--- trunk/KDE/kdebase/workspace/klipper/editactiondialog.cpp #947290:947291
@@ -39,7 +39,19 @@
m_ui->pbAddCommand->setIcon(KIcon("list-add"));
m_ui->pbRemoveCommand->setIcon(KIcon("list-remove"));
+ m_ui->twCommandList->header()->resizeSection( 0, 170 );
+
setMainWidget(dlgWidget);
+
+ connect(m_ui->twCommandList, SIGNAL(itemSelectionChanged()), SLOT(onSelectionChanged()));
+ connect(m_ui->twCommandList, SIGNAL(itemChanged(QTreeWidgetItem*, int)),
+ SLOT(onItemChanged(QTreeWidgetItem*, int)));
+
+ connect(m_ui->pbAddCommand, SIGNAL( clicked() ), SLOT( onAddCommand() ) );
+ connect(m_ui->pbRemoveCommand, SIGNAL( clicked() ), SLOT( onRemoveCommand() ) );
+
+ // update Remove button
+ onSelectionChanged();
}
EditActionDialog::~EditActionDialog()
@@ -68,10 +80,18 @@
foreach( const ClipCommand& cmd, m_action->commands() ) {
QTreeWidgetItem* item = new QTreeWidgetItem;
+ item->setFlags( item->flags() | Qt::ItemIsEditable );
+
item->setText( 0, cmd.command );
+ QString iconName = cmd.pixmap.isEmpty() ? "system-run" : cmd.pixmap;
+ item->setIcon( 0, KIcon( iconName ) );
+ item->setData( 0, Qt::UserRole, iconName ); // store icon name too
item->setText( 1, cmd.description );
m_ui->twCommandList->addTopLevelItem( item );
}
+
+ // update Remove button
+ onSelectionChanged();
}
void EditActionDialog::saveAction()
@@ -84,9 +104,16 @@
m_action->setRegExp( m_ui->leRegExp->text() );
m_action->setDescription( m_ui->leDescription->text() );
- //m_action->clearCommands();
+ m_action->clearCommands();
- //for
+ int cmdCount = m_ui->twCommandList->topLevelItemCount();
+ for ( int i=0; i<cmdCount; ++i ) {
+ QTreeWidgetItem* item = m_ui->twCommandList->topLevelItem( i );
+ // we store icon name in Qt::UserRole in first column
+ // (see onItemChanged())
+ QString iconName = item->data( 0, Qt::UserRole ).toString();
+ m_action->addCommand( item->text( 0 ), item->text( 1 ), true, iconName );
+ }
}
void EditActionDialog::slotButtonClicked( int button )
@@ -98,4 +125,56 @@
KDialog::slotButtonClicked( button );
}
+void EditActionDialog::onAddCommand()
+{
+ QTreeWidgetItem *item = new QTreeWidgetItem;
+ item->setFlags( item->flags() | Qt::ItemIsEditable );
+ item->setText( 0, i18n( "new command" ) );
+ item->setIcon( 0, KIcon( "system-run" ) );
+ item->setText( 1, i18n( "Command Description" ) );
+
+ m_ui->twCommandList->addTopLevelItem( item );
+ m_ui->twCommandList->editItem( item );
+}
+
+void EditActionDialog::onRemoveCommand()
+{
+ QTreeWidgetItem* curItem = m_ui->twCommandList->currentItem();
+ delete curItem;
+}
+
+void EditActionDialog::onItemChanged( QTreeWidgetItem* item, int column )
+{
+ if ( column == 0 ) {
+ // let's try to update icon of the item according to command
+ QString command = item->text( 0 );
+ if ( command.contains( ' ' ) )
+ // get first word
+ command = command.section( ' ', 0, 0 );
+
+ QPixmap iconPix = KIconLoader::global()->loadIcon(
+ command, KIconLoader::Small, 0,
+ KIconLoader::DefaultState,
+ QStringList(), 0, true /* canReturnNull */ );
+
+ // block signals to prevent infinite recursion when setIcon will trigger itemChanged again
+ m_ui->twCommandList->blockSignals( true );
+
+ if ( !iconPix.isNull() ) {
+ item->setIcon( 0, KIcon( command ) );
+ // let's save icon name in data field (if we found something that is not "system-run")
+ item->setData( 0, Qt::UserRole, command ); // command is actually the icon name here :)
+ } else {
+ item->setIcon( 0, KIcon( "system-run" ) );
+ }
+
+ m_ui->twCommandList->blockSignals( false );
+ }
+}
+
+void EditActionDialog::onSelectionChanged()
+{
+ m_ui->pbRemoveCommand->setEnabled( !m_ui->twCommandList->selectedItems().isEmpty() );
+}
+
#include "editactiondialog.moc"
--- trunk/KDE/kdebase/workspace/klipper/editactiondialog.h #947290:947291
@@ -29,6 +29,7 @@
}
class ClipAction;
+class QTreeWidgetItem;
class EditActionDialog : public KDialog
{
@@ -42,6 +43,12 @@
*/
void setAction(ClipAction* act);
+private slots:
+ void onAddCommand();
+ void onRemoveCommand();
+ void onSelectionChanged();
+ void onItemChanged( QTreeWidgetItem*, int );
+
private:
/**
* Updates dialog's widgets according to values
--- trunk/KDE/kdebase/workspace/klipper/editactiondialog.ui #947290:947291
@@ -6,7 +6,7 @@
<rect>
<x>0</x>
<y>0</y>
- <width>355</width>
+ <width>362</width>
<height>329</height>
</rect>
</property>
--- trunk/KDE/kdebase/workspace/klipper/urlgrabber.h #947290:947291
@@ -137,9 +137,9 @@
*/
void clearCommands() { m_myCommands.clear(); }
- void addCommand( const QString& command,
- const QString& description,
- bool isEnabled,
+ void addCommand( const QString& command,
+ const QString& description,
+ bool isEnabled = true,
const QString& icon = QString() );
/**
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic