28 #include <KFileDialog>
29 #include <KMessageBox>
32 #include <KStandardDirs>
34 #include <KIO/NetAccess>
37 #include <QHBoxLayout>
38 #include <QHeaderView>
40 #include <QPushButton>
41 #include <QTreeWidget>
50 mPath( path ), mIsActive( false )
57 if (!f.open( QFile::ReadOnly ) )
66 QImage img = pm.toImage().
scaled( 300, 300, Qt::KeepAspectRatio, Qt::SmoothTransformation );
83 Q_FOREACH ( it, list ) {
85 QString name = it->objectName();
89 << allowedTypes[
QLatin1String(it->metaObject()->className()) ]
114 void setIsActive(
bool isActive )
116 mIsActive = isActive;
119 bool isActive()
const
137 const QVariantList &args )
138 :
KCModule( instance, parent, args ),
147 ki18n(
"Qt Designer Fields Dialog" ),
148 0, KLocalizedString(), KAboutData::License_LGPL,
149 ki18n(
"(c), 2004 Tobias Koenig" ) );
151 about->addAuthor( ki18n(
"Tobias Koenig" ), KLocalizedString(),
"tokoe@kde.org" );
152 about->addAuthor( ki18n(
"Cornelius Schumacher" ), KLocalizedString(),
"schumacher@kde.org" );
153 setAboutData( about );
156 void KCMDesignerFields::delayedInit()
158 kDebug() <<
"KCMDesignerFields::delayedInit()";
162 connect( mPageView, SIGNAL(itemSelectionChanged()),
163 this, SLOT(updatePreview()) );
167 connect( mDeleteButton, SIGNAL(clicked()),
168 this, SLOT(deleteFile()) );
169 connect( mImportButton, SIGNAL(clicked()),
170 this, SLOT(importFile()) );
171 connect( mDesignerButton, SIGNAL(clicked()),
172 this, SLOT(startDesigner()) );
177 KDirWatch *dw =
new KDirWatch(
this );
179 dw->addDir(
localUiDir(), KDirWatch::WatchFiles );
180 connect( dw, SIGNAL(created(
QString)), SLOT(rebuildList()) );
181 connect( dw, SIGNAL(deleted(
QString)), SLOT(rebuildList()) );
182 connect( dw, SIGNAL(dirty(
QString)), SLOT(rebuildList()) );
185 void KCMDesignerFields::deleteFile()
188 PageItem *pageItem =
static_cast<PageItem*
>( item->
parent() ? item->
parent() : item );
189 if ( KMessageBox::warningContinueCancel(
191 i18n(
"<qt>Do you really want to delete '<b>%1</b>'?</qt>",
192 pageItem->text(0) ),
QString(), KStandardGuiItem::del() ) == KMessageBox::Continue ) {
193 KIO::NetAccess::del( pageItem->path(), 0 );
199 void KCMDesignerFields::importFile()
202 i18n(
"*.ui|Designer Files" ),
203 this, i18n(
"Import Page" ) );
206 dest.setFileName( src.fileName() );
207 KIO::Job *job = KIO::file_copy( src, dest, -1, KIO::Overwrite );
208 KIO::NetAccess::synchronousRun( job,
this );
216 KStandardDirs::Recursive |
217 KStandardDirs::NoDuplicates );
219 new PageItem( mPageView, *it );
223 void KCMDesignerFields::rebuildList()
239 if ( (*it)->parent() == 0 ) {
240 PageItem *item =
static_cast<PageItem*
>( *it );
241 if ( ai.
contains( item->name() ) ) {
242 item->setCheckState( 0, Qt::Checked );
243 item->setIsActive(
true );
263 QTreeWidgetItemIterator::Selectable );
267 if ( (*it)->parent() == 0 ) {
268 PageItem *item =
static_cast<PageItem*
>( *it );
269 activePages.
append( item->name() );
287 void KCMDesignerFields::initGUI()
291 layout->
setMargin( KDialog::marginHint() );
293 bool noDesigner = KStandardDirs::findExe(
QLatin1String(
"designer") ).isEmpty();
297 i18n(
"<qt><b>Warning:</b> Qt Designer could not be found. It is probably not "
298 "installed. You will only be able to import existing designer files.</qt>" );
317 mPagePreview =
new QLabel( box );
321 mPageDetails =
new QLabel( box );
334 i18n(
"<qt><p>This section allows you to add your own GUI"
335 " Elements ('<i>Widgets</i>') to store your own values"
336 " into %1. Proceed as described below:</p>"
338 "<li>Click on '<i>Edit with Qt Designer</i>'</li>"
339 "<li>In the dialog, select '<i>Widget</i>', then click <i>OK</i></li>"
340 "<li>Add your widgets to the form</li>"
341 "<li>Save the file in the directory proposed by Qt Designer</li>"
342 "<li>Close Qt Designer</li>"
344 "<p>In case you already have a designer file (*.ui) located"
345 " somewhere on your hard disk, simply choose '<i>Import Page</i>'</p>"
346 "<p><b>Important:</b> The name of each input widget you place within"
347 " the form must start with '<i>X_</i>'; so if you want the widget to"
348 " correspond to your custom entry '<i>X-Foo</i>', set the widget's"
349 " <i>name</i> property to '<i>X_Foo</i>'.</p>"
350 "<p><b>Important:</b> The widget will edit custom fields with an"
351 " application name of %2. To change the application name"
352 " to be edited, set the widget name in Qt Designer.</p></qt>",
356 i18n(
"<a href=\"whatsthis:%1\">How does this work?</a>", cwHowto ),
this );
358 Qt::LinksAccessibleByKeyboard );
360 connect( activeLabel, SIGNAL(linkActivated(
QString)),
361 this, SLOT(showWhatsThis(
QString)) );
365 activeLabel->
setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Maximum );
369 mDeleteButton =
new QPushButton( i18n(
"Delete Page" ),
this );
372 mImportButton =
new QPushButton( i18n(
"Import Page..." ),
this );
374 mDesignerButton =
new QPushButton( i18n(
"Edit with Qt Designer..." ),
this );
382 void KCMDesignerFields::updatePreview()
388 bool widgetItemSelected =
false;
393 "<tr><td align=\"right\"><b>%1</b></td><td>%2</td></tr>"
394 "<tr><td align=\"right\"><b>%3</b></td><td>%4</td></tr>"
395 "<tr><td align=\"right\"><b>%5</b></td><td>%6</td></tr>"
396 "<tr><td align=\"right\"><b>%7</b></td><td>%8</td></tr>"
398 .
arg( i18n(
"Key:" ) )
400 .arg( i18n(
"Type:" ) )
401 .arg( item->
text( 1 ) )
402 .arg( i18n(
"Classname:" ) )
403 .arg( item->
text( 2 ) )
404 .arg( i18n(
"Description:" ) )
405 .arg( item->
text( 3 ) );
407 mPageDetails->
setText( details );
409 PageItem *pageItem =
static_cast<PageItem*
>( item->
parent() );
414 PageItem *pageItem =
static_cast<PageItem*
>( item );
417 widgetItemSelected =
true;
420 mPagePreview->
setFrameStyle( QFrame::StyledPanel | QFrame::Sunken );
427 mDeleteButton->
setEnabled( widgetItemSelected );
432 if ( !item || item->
parent() != 0 ) {
436 PageItem *pageItem =
static_cast<PageItem*
>( item );
438 if ( pageItem->isOn() != pageItem->isActive() ) {
439 emit changed(
true );
440 pageItem->setIsActive( pageItem->isOn() );
444 void KCMDesignerFields::startDesigner()
450 if( !KGlobal::dirs()->exists(cepPath) ) {
451 KIO::NetAccess::mkdir( cepPath,
this );
462 PageItem *pageItem =
static_cast<PageItem*
>( item->
parent() ? item->
parent() : item );
463 cmdLine +=
QLatin1Char(
' ') + KShell::quoteArg( pageItem->path() );
466 KRun::runCommand( cmdLine, topLevelWidget() );
469 void KCMDesignerFields::showWhatsThis(
const QString &href )
KCMDesignerFields(const KComponentData &instance, QWidget *parent=0, const QVariantList &args=QVariantList())
void showText(const QPoint &pos, const QString &text, QWidget *w)
virtual void writeActivePages(const QStringList &)=0
void loadActivePages(const QStringList &)
bool contains(const Key &key) const
bool contains(const QString &str, Qt::CaseSensitivity cs) const
QPixmap fromImage(const QImage &image, QFlags< Qt::ImageConversionFlag > flags)
void setFrameStyle(int style)
int lastIndexOf(QChar ch, int from, Qt::CaseSensitivity cs) const
QList< T > findChildren(const QString &name) const
void append(const T &value)
virtual QString uiPath()=0
bool startsWith(const QString &s, Qt::CaseSensitivity cs) const
bool setCurrent(const QString &path)
void setText(const QString &)
void setAllColumnsShowFocus(bool enable)
void setMargin(int margin)
QByteArray toLocal8Bit() const
void setTextInteractionFlags(QFlags< Qt::TextInteractionFlag > flags)
QString & replace(int position, int n, QChar after)
QString mid(int position, int n) const
void addStretch(int stretch)
void setText(int column, const QString &text)
QWidget * load(QIODevice *device, QWidget *parentWidget)
QString fromLatin1(const char *str, int size)
QStringList saveActivePages()
iterator insert(const Key &key, const T &value)
virtual QString applicationName()=0
const_iterator constEnd() const
const_iterator constBegin() const
virtual QString localUiDir()=0
void setRootIsDecorated(bool show)
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const
QString text(int column) const
void setSpacing(int spacing)
QImage scaled(int width, int height, Qt::AspectRatioMode aspectRatioMode, Qt::TransformationMode transformMode) const
bool mkpath(const QString &dirPath) const
void addLayout(QLayout *layout, int stretch)
virtual QStringList readActivePages()=0