• Skip to content
  • Skip to link menu
KDE 4.7 API Reference
  • KDE API Reference
  • kdelibs
  • KDE Home
  • Contact Us
 

KIO

renamedialog.cpp
Go to the documentation of this file.
00001 /* This file is part of the KDE libraries
00002     Copyright (C) 2000 Stephan Kulow <coolo@kde.org>
00003                   1999 - 2008 David Faure <faure@kde.org>
00004                   2001, 2006 Holger Freyther <freyther@kde.org>
00005 
00006     This library is free software; you can redistribute it and/or
00007     modify it under the terms of the GNU Library General Public
00008     License as published by the Free Software Foundation; either
00009     version 2 of the License, or (at your option) any later version.
00010 
00011     This library is distributed in the hope that it will be useful,
00012     but WITHOUT ANY WARRANTY; without even the implied warranty of
00013     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014     Library General Public License for more details.
00015 
00016     You should have received a copy of the GNU Library General Public License
00017     along with this library; see the file COPYING.LIB.  If not, write to
00018     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00019     Boston, MA 02110-1301, USA.
00020 */
00021 
00022 #include "kio/renamedialog.h"
00023 #include <stdio.h>
00024 #include <assert.h>
00025 
00026 #include <QtCore/QDate>
00027 #include <QtCore/QFileInfo>
00028 #include <QtGui/QCheckBox>
00029 #include <QtGui/QLabel>
00030 #include <QtGui/QLayout>
00031 #include <QtGui/QPixmap>
00032 #include <QtGui/QScrollArea>
00033 #include <QtCore/QDir>
00034 
00035 #include <klineedit.h>
00036 #include <kmessagebox.h>
00037 #include <kpushbutton.h>
00038 #include <kio/global.h>
00039 #include <kio/udsentry.h>
00040 #include <kdialog.h>
00041 #include <klocale.h>
00042 #include <kglobal.h>
00043 #include <kdebug.h>
00044 #include <kurl.h>
00045 #include <kfileitem.h>
00046 #include <kmimetype.h>
00047 #include <kseparator.h>
00048 #include <kstringhandler.h>
00049 #include <kstandardguiitem.h>
00050 #include <kguiitem.h>
00051 #include <ksqueezedtextlabel.h>
00052 #include <kfilemetadatawidget.h>
00053 #include <previewjob.h>
00054 
00055 using namespace KIO;
00056 
00058 class RenameDialog::RenameDialogPrivate
00059 {
00060 public:
00061     RenameDialogPrivate() {
00062         bCancel = 0;
00063         bRename = bSkip = bOverwrite = 0;
00064         bResume = bSuggestNewName = 0;
00065         bApplyAll = 0;
00066         m_pLineEdit = 0;
00067         m_srcPendingPreview = false;
00068         m_destPendingPreview = false;
00069         m_srcPreview = 0;
00070         m_destPreview = 0;
00071     }
00072 
00073     void setRenameBoxText(const QString& fileName) {
00074         // sets the text in file name line edit box, selecting the filename (but not the extension if there is one).
00075         const QString extension = KMimeType::extractKnownExtension(fileName);
00076         m_pLineEdit->setText(fileName);
00077 
00078         if (!extension.isEmpty()) {
00079             const int selectionLength = fileName.length() - extension.length() - 1;
00080             m_pLineEdit->setSelection(0, selectionLength);
00081         } else {
00082             m_pLineEdit->selectAll();
00083         }
00084     }
00085 
00086     KPushButton *bCancel;
00087     QPushButton *bRename;
00088     QPushButton *bSkip;
00089     QPushButton *bOverwrite;
00090     QPushButton *bResume;
00091     QPushButton *bSuggestNewName;
00092     QCheckBox *bApplyAll;
00093     KLineEdit* m_pLineEdit;
00094     KUrl src;
00095     KUrl dest;
00096     bool m_srcPendingPreview;
00097     bool m_destPendingPreview;
00098     QLabel* m_srcPreview;
00099     QLabel* m_destPreview;
00100 };
00101 
00102 RenameDialog::RenameDialog(QWidget *parent, const QString & _caption,
00103                            const KUrl &_src, const KUrl &_dest,
00104                            RenameDialog_Mode _mode,
00105                            KIO::filesize_t sizeSrc,
00106                            KIO::filesize_t sizeDest,
00107                            time_t ctimeSrc,
00108                            time_t ctimeDest,
00109                            time_t mtimeSrc,
00110                            time_t mtimeDest)
00111         : QDialog(parent), d(new RenameDialogPrivate)
00112 {
00113     setObjectName("KIO::RenameDialog");
00114 
00115     d->src = _src;
00116     d->dest = _dest;
00117 
00118     setWindowTitle(_caption);
00119 
00120     d->bCancel = new KPushButton(KStandardGuiItem::cancel(), this);
00121     connect(d->bCancel, SIGNAL(clicked()), this, SLOT(cancelPressed()));
00122 
00123     if (_mode & M_MULTI) {
00124         d->bApplyAll = new QCheckBox(i18n("Appl&y to All"), this);
00125         d->bApplyAll->setToolTip((_mode & M_ISDIR) ? i18n("When this is checked the button pressed will be applied to all subsequent folder conflicts for the remainder of the current job.\nUnless you press Skip you will still be prompted in case of a conflict with an existing file in the directory.")
00126                                  : i18n("When this is checked the button pressed will be applied to all subsequent conflicts for the remainder of the current job."));
00127         connect(d->bApplyAll, SIGNAL(clicked()), this, SLOT(applyAllPressed()));
00128     }
00129 
00130     if (!(_mode & M_NORENAME)) {
00131         d->bRename = new QPushButton(i18n("&Rename"), this);
00132         d->bRename->setEnabled(false);
00133         d->bSuggestNewName = new QPushButton(i18n("Suggest New &Name"), this);
00134         connect(d->bSuggestNewName, SIGNAL(clicked()), this, SLOT(suggestNewNamePressed()));
00135         connect(d->bRename, SIGNAL(clicked()), this, SLOT(renamePressed()));
00136     }
00137 
00138     if ((_mode & M_MULTI) && (_mode & M_SKIP)) {
00139         d->bSkip = new QPushButton(i18n("&Skip"), this);
00140         d->bSkip->setToolTip((_mode & M_ISDIR) ? i18n("Do not copy or move this folder, skip to the next item instead")
00141                              : i18n("Do not copy or move this file, skip to the next item instead"));
00142         connect(d->bSkip, SIGNAL(clicked()), this, SLOT(skipPressed()));
00143     }
00144 
00145     if (_mode & M_OVERWRITE) {
00146         const QString text = (_mode & M_ISDIR) ? i18nc("Write files into an existing folder", "&Write Into") : i18n("&Overwrite");
00147         d->bOverwrite = new QPushButton(text, this);
00148         d->bOverwrite->setToolTip(i18n("Files and folders will be copied into the existing directory, alongside its existing contents.\nYou will be prompted again in case of a conflict with an existing file in the directory."));
00149         connect(d->bOverwrite, SIGNAL(clicked()), this, SLOT(overwritePressed()));
00150     }
00151 
00152     if (_mode & M_RESUME) {
00153         d->bResume = new QPushButton(i18n("&Resume"), this);
00154         connect(d->bResume, SIGNAL(clicked()), this, SLOT(resumePressed()));
00155     }
00156 
00157     QVBoxLayout* pLayout = new QVBoxLayout(this);
00158     pLayout->addStrut(400);     // makes dlg at least that wide
00159 
00160     // User tries to overwrite a file with itself ?
00161     if (_mode & M_OVERWRITE_ITSELF) {
00162         QLabel *lb = new QLabel(i18n("This action would overwrite '%1' with itself.\n"
00163                                      "Please enter a new file name:",
00164                                      KStringHandler::csqueeze(d->src.pathOrUrl(), 100)), this);
00165 
00166         d->bRename->setText(i18n("C&ontinue"));
00167         pLayout->addWidget(lb);
00168     } else if (_mode & M_OVERWRITE) {
00169         KFileItem srcItem;
00170         KFileItem destItem;
00171 
00172         if (d->src.isLocalFile()) {
00173             srcItem = KFileItem(KFileItem::Unknown, KFileItem::Unknown, d->src);
00174         } else {
00175             UDSEntry srcUds;
00176 
00177             srcUds.insert(UDSEntry::UDS_NAME, d->src.fileName());
00178             srcUds.insert(UDSEntry::UDS_MODIFICATION_TIME, mtimeSrc);
00179             srcUds.insert(UDSEntry::UDS_CREATION_TIME, ctimeSrc);
00180             srcUds.insert(UDSEntry::UDS_SIZE, sizeSrc);
00181 
00182             srcItem = KFileItem(srcUds, d->src);
00183         }
00184 
00185         if (d->dest.isLocalFile()) {
00186             destItem = KFileItem(KFileItem::Unknown, KFileItem::Unknown, d->dest);
00187         } else {
00188             UDSEntry destUds;
00189 
00190             destUds.insert(UDSEntry::UDS_NAME, d->dest.fileName());
00191             destUds.insert(UDSEntry::UDS_MODIFICATION_TIME, mtimeDest);
00192             destUds.insert(UDSEntry::UDS_CREATION_TIME, ctimeDest);
00193             destUds.insert(UDSEntry::UDS_SIZE, sizeDest);
00194 
00195             destItem = KFileItem(destUds, d->dest);
00196         }
00197 
00198         d->m_srcPreview = createLabel(parent, QString(), false);
00199         d->m_destPreview = createLabel(parent, QString(), false);
00200 
00201         d->m_srcPreview->setMinimumHeight(KIconLoader::SizeEnormous);
00202         d->m_destPreview->setMinimumHeight(KIconLoader::SizeEnormous);
00203 
00204         d->m_srcPendingPreview = true;
00205         d->m_destPendingPreview = true;
00206 
00207         KIO::PreviewJob* srcJob = KIO::filePreview(KFileItemList() << srcItem,
00208                                   QSize(d->m_srcPreview->width(), d->m_srcPreview->height()));
00209         srcJob->setScaleType(KIO::PreviewJob::Unscaled);
00210 
00211         KIO::PreviewJob* destJob = KIO::filePreview(KFileItemList() << destItem,
00212                                    QSize(d->m_destPreview->width(), d->m_destPreview->height()));
00213         destJob->setScaleType(KIO::PreviewJob::Unscaled);
00214 
00215         connect(srcJob, SIGNAL(gotPreview(const KFileItem&, const QPixmap&)),
00216                 this, SLOT(showSrcPreview(const KFileItem&, const QPixmap&)));
00217         connect(destJob, SIGNAL(gotPreview(const KFileItem&, const QPixmap&)),
00218                 this, SLOT(showDestPreview(const KFileItem&, const QPixmap&)));
00219         connect(srcJob, SIGNAL(failed(const KFileItem&)),
00220                 this, SLOT(showSrcIcon(const KFileItem&)));
00221         connect(destJob, SIGNAL(failed(const KFileItem&)),
00222                 this, SLOT(showDestIcon(const KFileItem&)));
00223 
00224         // widget
00225         QScrollArea* srcWidget = createContainerLayout(parent, srcItem, d->m_srcPreview);
00226         QScrollArea* destWidget = createContainerLayout(parent, destItem, d->m_destPreview);
00227 
00228         // create layout
00229         QGridLayout* gridLayout = new QGridLayout();
00230         pLayout->addLayout(gridLayout);
00231 
00232         QLabel* titleLabel = new QLabel(i18n("This action will overwrite the destination."), this);
00233 
00234         QLabel* srcTitle = createLabel(parent, i18n("Source"), true);
00235         QLabel* destTitle = createLabel(parent, i18n("Destination"), true);
00236 
00237         QLabel* srcInfo = createSqueezedLabel(parent, d->src.pathOrUrl());
00238         QLabel* destInfo = createSqueezedLabel(parent, d->dest.pathOrUrl());
00239 
00240         if (mtimeDest > mtimeSrc) {
00241             QLabel* warningLabel = new QLabel(i18n("Warning, the destination is more recent."), this);
00242 
00243             gridLayout->addWidget(titleLabel, 0, 0, 1, 2);    // takes the complete first line
00244             gridLayout->addWidget(warningLabel, 1, 0, 1, 2);
00245             gridLayout->setRowMinimumHeight(2, 15);    // spacer
00246 
00247             gridLayout->addWidget(srcTitle, 3, 0);
00248             gridLayout->addWidget(srcInfo, 4, 0);
00249             gridLayout->addWidget(srcWidget, 5, 0);
00250 
00251             gridLayout->addWidget(destTitle, 3, 1);
00252             gridLayout->addWidget(destInfo, 4, 1);
00253             gridLayout->addWidget(destWidget, 5, 1);
00254         } else {
00255             gridLayout->addWidget(titleLabel, 0, 0, 1, 2);
00256             gridLayout->setRowMinimumHeight(1, 15);
00257 
00258             gridLayout->addWidget(srcTitle, 2, 0);
00259             gridLayout->addWidget(srcInfo, 3, 0);
00260             gridLayout->addWidget(srcWidget, 4, 0);
00261 
00262             gridLayout->addWidget(destTitle, 2, 1);
00263             gridLayout->addWidget(destInfo, 3, 1);
00264             gridLayout->addWidget(destWidget, 4, 1);
00265         }
00266     } else {
00267         // This is the case where we don't want to allow overwriting, the existing
00268         // file must be preserved (e.g. when renaming).
00269         QString sentence1;
00270 
00271         if (mtimeDest < mtimeSrc)
00272             sentence1 = i18n("An older item named '%1' already exists.", d->dest.pathOrUrl());
00273         else if (mtimeDest == mtimeSrc)
00274             sentence1 = i18n("A similar file named '%1' already exists.", d->dest.pathOrUrl());
00275         else
00276             sentence1 = i18n("A more recent item named '%1' already exists.", d->dest.pathOrUrl());
00277 
00278         QLabel *lb = new KSqueezedTextLabel(sentence1, this);
00279         pLayout->addWidget(lb);
00280     }
00281 
00282     if ((_mode != M_OVERWRITE_ITSELF) && (_mode != M_NORENAME)) {
00283         if (_mode == M_OVERWRITE) {
00284             pLayout->addSpacing(15);    // spacer
00285         }
00286 
00287         QLabel *lb2 = new QLabel(i18n("Rename:"), this);
00288         pLayout->addWidget(lb2);
00289     }
00290 
00291     QHBoxLayout* layout2 = new QHBoxLayout();
00292     pLayout->addLayout(layout2);
00293 
00294     d->m_pLineEdit = new KLineEdit(this);
00295     layout2->addWidget(d->m_pLineEdit);
00296 
00297     if (d->bRename) {
00298         const QString fileName = d->dest.fileName();
00299         d->setRenameBoxText(KIO::decodeFileName(fileName));
00300 
00301         connect(d->m_pLineEdit, SIGNAL(textChanged(const QString &)),
00302                 SLOT(enableRenameButton(const QString &)));
00303 
00304         d->m_pLineEdit->setFocus();
00305     } else {
00306         d->m_pLineEdit->hide();
00307     }
00308 
00309     if (d->bSuggestNewName) {
00310         layout2->addWidget(d->bSuggestNewName);
00311         setTabOrder(d->m_pLineEdit, d->bSuggestNewName);
00312     }
00313 
00314     KSeparator* separator = new KSeparator(this);
00315     pLayout->addWidget(separator);
00316 
00317     QHBoxLayout* layout = new QHBoxLayout();
00318     pLayout->addLayout(layout);
00319 
00320     layout->addStretch(1);
00321 
00322     if (d->bApplyAll) {
00323         layout->addWidget(d->bApplyAll);
00324         setTabOrder(d->bApplyAll, d->bCancel);
00325     }
00326 
00327     if (d->bRename) {
00328         layout->addWidget(d->bRename);
00329         setTabOrder(d->bRename, d->bCancel);
00330     }
00331 
00332     if (d->bSkip) {
00333         layout->addWidget(d->bSkip);
00334         setTabOrder(d->bSkip, d->bCancel);
00335     }
00336 
00337     if (d->bOverwrite) {
00338         layout->addWidget(d->bOverwrite);
00339         setTabOrder(d->bOverwrite, d->bCancel);
00340     }
00341 
00342     if (d->bResume) {
00343         layout->addWidget(d->bResume);
00344         setTabOrder(d->bResume, d->bCancel);
00345     }
00346 
00347     d->bCancel->setDefault(true);
00348     layout->addWidget(d->bCancel);
00349 
00350     resize(sizeHint());
00351 }
00352 
00353 RenameDialog::~RenameDialog()
00354 {
00355     delete d;
00356     // no need to delete Pushbuttons,... qt will do this
00357 }
00358 
00359 void RenameDialog::enableRenameButton(const QString &newDest)
00360 {
00361     if (newDest != KIO::decodeFileName(d->dest.fileName()) && !newDest.isEmpty()) {
00362         d->bRename->setEnabled(true);
00363         d->bRename->setDefault(true);
00364 
00365         if (d->bOverwrite) {
00366             d->bOverwrite->setEnabled(false);   // prevent confusion (#83114)
00367         }
00368     } else {
00369         d->bRename->setEnabled(false);
00370 
00371         if (d->bOverwrite) {
00372             d->bOverwrite->setEnabled(true);
00373         }
00374     }
00375 }
00376 
00377 KUrl RenameDialog::newDestUrl()
00378 {
00379     KUrl newDest(d->dest);
00380     QString fileName = d->m_pLineEdit->text();
00381 
00382     newDest.setFileName(KIO::encodeFileName(fileName));
00383 
00384     return newDest;
00385 }
00386 
00387 KUrl RenameDialog::autoDestUrl() const
00388 {
00389     KUrl newDest(d->dest);
00390     KUrl destDirectory(d->dest);
00391 
00392     destDirectory.setPath(destDirectory.directory());
00393     newDest.setFileName(suggestName(destDirectory, d->dest.fileName()));
00394 
00395     return newDest;
00396 }
00397 
00398 void RenameDialog::cancelPressed()
00399 {
00400     done(R_CANCEL);
00401 }
00402 
00403 // Rename
00404 void RenameDialog::renamePressed()
00405 {
00406     if (d->m_pLineEdit->text().isEmpty()) {
00407         return;
00408     }
00409 
00410     if (d->bApplyAll  && d->bApplyAll->isChecked()) {
00411         done(R_AUTO_RENAME);
00412     } else {
00413         KUrl u = newDestUrl();
00414 
00415         if (!u.isValid()) {
00416             KMessageBox::error(this, i18n("Malformed URL\n%1" ,  u.url()));
00417             return;
00418         }
00419 
00420         done(R_RENAME);
00421     }
00422 }
00423 
00424 QString RenameDialog::suggestName(const KUrl& baseURL, const QString& oldName)
00425 {
00426     QString dotSuffix, suggestedName;
00427     QString basename = oldName;
00428     const QChar spacer(' ');
00429 
00430     //ignore dots at the beginning, that way "..aFile.tar.gz" will become "..aFile 1.tar.gz" instead of " 1..aFile.tar.gz"
00431     int index = basename.indexOf('.');
00432     int continous = 0;
00433     while (continous == index) {
00434         index = basename.indexOf('.', index + 1);
00435         ++continous;
00436     }
00437 
00438     if (index != -1) {
00439         dotSuffix = basename.mid(index);
00440         basename.truncate(index);
00441     }
00442 
00443     int pos = basename.lastIndexOf(spacer);
00444 
00445     if (pos != -1) {
00446         QString tmp = basename.mid(pos + 1);
00447         bool ok;
00448         int number = tmp.toInt(&ok);
00449 
00450         if (!ok) {  // ok there is no number
00451             suggestedName = basename + spacer + '1' + dotSuffix;
00452         } else {
00453             // yes there's already a number behind the spacer so increment it by one
00454             basename.replace(pos + 1, tmp.length(), QString::number(number + 1));
00455             suggestedName = basename + dotSuffix;
00456         }
00457     } else // no spacer yet
00458         suggestedName = basename + spacer + "1" + dotSuffix ;
00459 
00460     // Check if suggested name already exists
00461     bool exists = false;
00462     // TODO: network transparency. However, using NetAccess from a modal dialog
00463     // could be a problem, no? (given that it uses a modal widget itself....)
00464     if (baseURL.isLocalFile())
00465         exists = QFileInfo(baseURL.toLocalFile(KUrl::AddTrailingSlash) + suggestedName).exists();
00466 
00467     if (!exists)
00468         return suggestedName;
00469     else // already exists -> recurse
00470         return suggestName(baseURL, suggestedName);
00471 }
00472 
00473 // Propose button clicked
00474 void RenameDialog::suggestNewNamePressed()
00475 {
00476     /* no name to play with */
00477     if (d->m_pLineEdit->text().isEmpty())
00478         return;
00479 
00480     KUrl destDirectory(d->dest);
00481 
00482     destDirectory.setPath(destDirectory.directory());
00483     d->setRenameBoxText(suggestName(destDirectory, d->m_pLineEdit->text()));
00484 
00485     return;
00486 }
00487 
00488 void RenameDialog::skipPressed()
00489 {
00490     if (d->bApplyAll  && d->bApplyAll->isChecked()) {
00491         done(R_AUTO_SKIP);
00492     } else {
00493         done(R_SKIP);
00494     }
00495 }
00496 
00497 void RenameDialog::autoSkipPressed()
00498 {
00499     done(R_AUTO_SKIP);
00500 }
00501 
00502 void RenameDialog::overwritePressed()
00503 {
00504     if (d->bApplyAll  && d->bApplyAll->isChecked()) {
00505         done(R_OVERWRITE_ALL);
00506     } else {
00507         done(R_OVERWRITE);
00508     }
00509 }
00510 
00511 void RenameDialog::overwriteAllPressed()
00512 {
00513     done(R_OVERWRITE_ALL);
00514 }
00515 
00516 void RenameDialog::resumePressed()
00517 {
00518     if (d->bApplyAll  && d->bApplyAll->isChecked()) {
00519         done(R_RESUME_ALL);
00520     } else {
00521         done(R_RESUME);
00522     }
00523 }
00524 
00525 void RenameDialog::resumeAllPressed()
00526 {
00527     done(R_RESUME_ALL);
00528 }
00529 
00530 void RenameDialog::applyAllPressed()
00531 {
00532     if (d->bApplyAll  && d->bApplyAll->isChecked()) {
00533         d->m_pLineEdit->setText(KIO::decodeFileName(d->dest.fileName()));
00534         d->m_pLineEdit->setEnabled(false);
00535 
00536         if (d->bRename) {
00537             d->bRename->setEnabled(true);
00538         }
00539 
00540         if (d->bSuggestNewName) {
00541             d->bSuggestNewName->setEnabled(false);
00542         }
00543     } else {
00544         d->m_pLineEdit->setEnabled(true);
00545 
00546         if (d->bRename) {
00547             d->bRename->setEnabled(false);
00548         }
00549 
00550         if (d->bSuggestNewName) {
00551             d->bSuggestNewName->setEnabled(true);
00552         }
00553     }
00554 }
00555 
00556 void RenameDialog::showSrcIcon(const KFileItem& fileitem)
00557 {
00558     // The preview job failed, show a standard file icon.
00559     d->m_srcPendingPreview = false;
00560     d->m_srcPreview->setPixmap(fileitem.pixmap(d->m_srcPreview->height()));
00561 }
00562 
00563 void RenameDialog::showDestIcon(const KFileItem& fileitem)
00564 {
00565     // The preview job failed, show a standard file icon.
00566     d->m_destPendingPreview = false;
00567     d->m_destPreview->setPixmap(fileitem.pixmap(d->m_srcPreview->height()));
00568 }
00569 
00570 void RenameDialog::showSrcPreview(const KFileItem& fileitem, const QPixmap& pixmap)
00571 {
00572     Q_UNUSED(fileitem);
00573 
00574     if (d->m_srcPendingPreview) {
00575         d->m_srcPreview->setPixmap(pixmap);
00576         d->m_srcPendingPreview = false;
00577     }
00578 }
00579 
00580 void RenameDialog::showDestPreview(const KFileItem& fileitem, const QPixmap& pixmap)
00581 {
00582     Q_UNUSED(fileitem);
00583 
00584     if (d->m_destPendingPreview) {
00585         d->m_destPreview->setPixmap(pixmap);
00586         d->m_destPendingPreview = false;
00587     }
00588 }
00589 
00590 QScrollArea* RenameDialog::createContainerLayout(QWidget* parent, const KFileItem& item, QLabel* preview)
00591 {
00592     KFileItemList itemList;
00593     itemList << item;
00594 
00595     // widget
00596     KFileMetaDataWidget* metaWidget =  new KFileMetaDataWidget(this);
00597 
00598     metaWidget->setReadOnly(true);
00599     metaWidget->setItems(itemList);
00600 
00601     // Encapsulate the MetaDataWidgets inside a container with stretch at the bottom.
00602     // This prevents that the meta data widgets get vertically stretched
00603     // in the case where the height of m_metaDataArea > m_metaDataWidget.
00604 
00605     QWidget* widgetContainer = new QWidget(parent);
00606     QVBoxLayout* containerLayout = new QVBoxLayout(widgetContainer);
00607 
00608     containerLayout->setContentsMargins(0, 0, 0, 0);
00609     containerLayout->setSpacing(0);
00610     containerLayout->addWidget(preview);
00611     containerLayout->addWidget(metaWidget);
00612     containerLayout->addStretch(1);
00613 
00614     QScrollArea* metaDataArea = new QScrollArea(parent);
00615 
00616     metaDataArea->setWidget(widgetContainer);
00617     metaDataArea->setWidgetResizable(true);
00618     metaDataArea->setFrameShape(QFrame::NoFrame);
00619 
00620     return metaDataArea;
00621 }
00622 
00623 QLabel* RenameDialog::createLabel(QWidget* parent, const QString& text, bool containerTitle)
00624 {
00625     QLabel* label = new QLabel(parent);
00626 
00627     if (containerTitle) {
00628         QFont font = label->font();
00629         font.setBold(true);
00630         label->setFont(font);
00631     }
00632 
00633     label->setAlignment(Qt::AlignHCenter);
00634     label->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed);
00635     label->setText(text);
00636 
00637     return label;
00638 }
00639 
00640 KSqueezedTextLabel* RenameDialog::createSqueezedLabel(QWidget* parent, const QString& text)
00641 {
00642     KSqueezedTextLabel* label = new KSqueezedTextLabel(text, parent);
00643 
00644     label->setAlignment(Qt::AlignHCenter);
00645     label->setFixedWidth(200);
00646 
00647     return label;
00648 }
00649 
00650 #include "renamedialog.moc"

KIO

Skip menu "KIO"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.7.5
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal