KFile
kurlnavigatorbutton.cpp
Go to the documentation of this file.
00001 /***************************************************************************** 00002 * Copyright (C) 2006 by Peter Penz <peter.penz@gmx.at> * 00003 * Copyright (C) 2006 by Aaron J. Seigo <aseigo@kde.org> * 00004 * * 00005 * This library is free software; you can redistribute it and/or * 00006 * modify it under the terms of the GNU Library General Public * 00007 * License as published by the Free Software Foundation; either * 00008 * version 2 of the License, or (at your option) any later version. * 00009 * * 00010 * This library is distributed in the hope that it will be useful, * 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * 00013 * Library General Public License for more details. * 00014 * * 00015 * You should have received a copy of the GNU Library General Public License * 00016 * along with this library; see the file COPYING.LIB. If not, write to * 00017 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * 00018 * Boston, MA 02110-1301, USA. * 00019 *****************************************************************************/ 00020 00021 #include "kurlnavigatorbutton_p.h" 00022 00023 #include "kurlnavigator.h" 00024 #include "kurlnavigatormenu_p.h" 00025 #include "kdirsortfilterproxymodel.h" 00026 00027 #include <kio/job.h> 00028 #include <kio/jobclasses.h> 00029 #include <kglobalsettings.h> 00030 #include <klocale.h> 00031 #include <kstringhandler.h> 00032 00033 #include <QtCore/QTimer> 00034 #include <QtGui/QPainter> 00035 #include <QtGui/QKeyEvent> 00036 #include <QtGui/QStyleOption> 00037 00038 namespace KDEPrivate 00039 { 00040 00041 QPointer<KUrlNavigatorMenu> KUrlNavigatorButton::m_subDirsMenu; 00042 00043 KUrlNavigatorButton::KUrlNavigatorButton(const KUrl& url, QWidget* parent) : 00044 KUrlNavigatorButtonBase(parent), 00045 m_hoverArrow(false), 00046 m_pendingTextChange(false), 00047 m_replaceButton(false), 00048 m_showMnemonic(false), 00049 m_wheelSteps(0), 00050 m_url(url), 00051 m_subDir(), 00052 m_openSubDirsTimer(0), 00053 m_subDirsJob(0) 00054 { 00055 setAcceptDrops(true); 00056 setUrl(url); 00057 setMouseTracking(true); 00058 00059 m_openSubDirsTimer = new QTimer(this); 00060 m_openSubDirsTimer->setSingleShot(true); 00061 m_openSubDirsTimer->setInterval(300); 00062 connect(m_openSubDirsTimer, SIGNAL(timeout()), this, SLOT(startSubDirsJob())); 00063 00064 connect(this, SIGNAL(pressed()), this, SLOT(requestSubDirs())); 00065 } 00066 00067 KUrlNavigatorButton::~KUrlNavigatorButton() 00068 { 00069 } 00070 00071 void KUrlNavigatorButton::setUrl(const KUrl& url) 00072 { 00073 m_url = url; 00074 00075 bool startTextResolving = !m_url.isLocalFile(); 00076 if (startTextResolving) { 00077 // Doing a text-resolving with KIO::stat() for all non-local 00078 // URLs leads to problems for protocols where a limit is given for 00079 // the number of parallel connections. A black-list 00080 // is given where KIO::stat() should not be used: 00081 static QSet<QString> protocols; 00082 if (protocols.isEmpty()) { 00083 protocols << "fish" << "ftp" << "nfs" << "sftp" << "smb" << "webdav"; 00084 } 00085 startTextResolving = !protocols.contains(m_url.protocol()); 00086 } 00087 00088 if (startTextResolving) { 00089 m_pendingTextChange = true; 00090 KIO::StatJob* job = KIO::stat(m_url, KIO::HideProgressInfo); 00091 connect(job, SIGNAL(result(KJob*)), 00092 this, SLOT(statFinished(KJob*))); 00093 emit startedTextResolving(); 00094 } else { 00095 setText(m_url.fileName().replace('&', "&&")); 00096 } 00097 } 00098 00099 KUrl KUrlNavigatorButton::url() const 00100 { 00101 return m_url; 00102 } 00103 00104 void KUrlNavigatorButton::setText(const QString& text) 00105 { 00106 QString adjustedText = text; 00107 if (adjustedText.isEmpty()) { 00108 adjustedText = m_url.protocol(); 00109 } 00110 // Assure that the button always consists of one line 00111 adjustedText.remove(QLatin1Char('\n')); 00112 00113 KUrlNavigatorButtonBase::setText(adjustedText); 00114 updateMinimumWidth(); 00115 00116 // Assure that statFinished() does not overwrite a text that has been 00117 // set by a client of the URL navigator button 00118 m_pendingTextChange = false; 00119 } 00120 00121 void KUrlNavigatorButton::setActiveSubDirectory(const QString& subDir) 00122 { 00123 m_subDir = subDir; 00124 00125 // We use a different (bold) font on active, so the size hint changes 00126 updateGeometry(); 00127 update(); 00128 } 00129 00130 QString KUrlNavigatorButton::activeSubDirectory() const 00131 { 00132 return m_subDir; 00133 } 00134 00135 QSize KUrlNavigatorButton::sizeHint() const 00136 { 00137 QFont adjustedFont(font()); 00138 adjustedFont.setBold(m_subDir.isEmpty()); 00139 // the minimum size is textWidth + arrowWidth() + 2 * BorderWidth; for the 00140 // preferred size we add the BorderWidth 2 times again for having an uncluttered look 00141 const int width = QFontMetrics(adjustedFont).width(plainText()) + arrowWidth() + 4 * BorderWidth; 00142 return QSize(width, KUrlNavigatorButtonBase::sizeHint().height()); 00143 } 00144 00145 void KUrlNavigatorButton::setShowMnemonic(bool show) 00146 { 00147 if (m_showMnemonic != show) { 00148 m_showMnemonic = show; 00149 update(); 00150 } 00151 } 00152 00153 bool KUrlNavigatorButton::showMnemonic() const 00154 { 00155 return m_showMnemonic; 00156 } 00157 00158 void KUrlNavigatorButton::paintEvent(QPaintEvent* event) 00159 { 00160 Q_UNUSED(event); 00161 00162 QPainter painter(this); 00163 00164 QFont adjustedFont(font()); 00165 adjustedFont.setBold(m_subDir.isEmpty()); 00166 painter.setFont(adjustedFont); 00167 00168 int buttonWidth = width(); 00169 int preferredWidth = sizeHint().width(); 00170 if (preferredWidth < minimumWidth()) { 00171 preferredWidth = minimumWidth(); 00172 } 00173 if (buttonWidth > preferredWidth) { 00174 buttonWidth = preferredWidth; 00175 } 00176 const int buttonHeight = height(); 00177 00178 const QColor fgColor = foregroundColor(); 00179 drawHoverBackground(&painter); 00180 00181 int textLeft = 0; 00182 int textWidth = buttonWidth; 00183 00184 const bool leftToRight = (layoutDirection() == Qt::LeftToRight); 00185 00186 if (!m_subDir.isEmpty()) { 00187 // draw arrow 00188 const int arrowSize = arrowWidth(); 00189 const int arrowX = leftToRight ? (buttonWidth - arrowSize) - BorderWidth : BorderWidth; 00190 const int arrowY = (buttonHeight - arrowSize) / 2; 00191 00192 QStyleOption option; 00193 option.initFrom(this); 00194 option.rect = QRect(arrowX, arrowY, arrowSize, arrowSize); 00195 option.palette = palette(); 00196 option.palette.setColor(QPalette::Text, fgColor); 00197 option.palette.setColor(QPalette::WindowText, fgColor); 00198 option.palette.setColor(QPalette::ButtonText, fgColor); 00199 00200 if (m_hoverArrow) { 00201 // highlight the background of the arrow to indicate that the directories 00202 // popup can be opened by a mouse click 00203 QColor hoverColor = palette().color(QPalette::HighlightedText); 00204 hoverColor.setAlpha(96); 00205 painter.setPen(Qt::NoPen); 00206 painter.setBrush(hoverColor); 00207 00208 int hoverX = arrowX; 00209 if (!leftToRight) { 00210 hoverX -= BorderWidth; 00211 } 00212 painter.drawRect(QRect(hoverX, 0, arrowSize + BorderWidth, buttonHeight)); 00213 } 00214 00215 if (leftToRight) { 00216 style()->drawPrimitive(QStyle::PE_IndicatorArrowRight, &option, &painter, this); 00217 } else { 00218 style()->drawPrimitive(QStyle::PE_IndicatorArrowLeft, &option, &painter, this); 00219 textLeft += arrowSize + 2 * BorderWidth; 00220 } 00221 00222 textWidth -= arrowSize + 2 * BorderWidth; 00223 } 00224 00225 painter.setPen(fgColor); 00226 const bool clipped = isTextClipped(); 00227 const QRect textRect(textLeft, 0, textWidth, buttonHeight); 00228 if (clipped) { 00229 QColor bgColor = fgColor; 00230 bgColor.setAlpha(0); 00231 QLinearGradient gradient(textRect.topLeft(), textRect.topRight()); 00232 if (leftToRight) { 00233 gradient.setColorAt(0.8, fgColor); 00234 gradient.setColorAt(1.0, bgColor); 00235 } else { 00236 gradient.setColorAt(0.0, bgColor); 00237 gradient.setColorAt(0.2, fgColor); 00238 } 00239 00240 QPen pen; 00241 pen.setBrush(QBrush(gradient)); 00242 painter.setPen(pen); 00243 } 00244 00245 int textFlags = clipped ? Qt::AlignVCenter : Qt::AlignCenter; 00246 if (m_showMnemonic) { 00247 textFlags |= Qt::TextShowMnemonic; 00248 painter.drawText(textRect, textFlags, text()); 00249 } else { 00250 painter.drawText(textRect, textFlags, plainText()); 00251 } 00252 } 00253 00254 void KUrlNavigatorButton::enterEvent(QEvent* event) 00255 { 00256 KUrlNavigatorButtonBase::enterEvent(event); 00257 00258 // if the text is clipped due to a small window width, the text should 00259 // be shown as tooltip 00260 if (isTextClipped()) { 00261 setToolTip(plainText()); 00262 } 00263 } 00264 00265 void KUrlNavigatorButton::leaveEvent(QEvent* event) 00266 { 00267 KUrlNavigatorButtonBase::leaveEvent(event); 00268 setToolTip(QString()); 00269 00270 if (m_hoverArrow) { 00271 m_hoverArrow = false; 00272 update(); 00273 } 00274 } 00275 00276 void KUrlNavigatorButton::keyPressEvent(QKeyEvent* event) 00277 { 00278 switch (event->key()) { 00279 case Qt::Key_Enter: 00280 case Qt::Key_Return: 00281 emit clicked(m_url, Qt::LeftButton); 00282 break; 00283 case Qt::Key_Down: 00284 case Qt::Key_Space: 00285 startSubDirsJob(); 00286 break; 00287 default: 00288 KUrlNavigatorButtonBase::keyPressEvent(event); 00289 } 00290 } 00291 00292 void KUrlNavigatorButton::dropEvent(QDropEvent* event) 00293 { 00294 const KUrl::List urls = KUrl::List::fromMimeData(event->mimeData()); 00295 if (!urls.isEmpty()) { 00296 setDisplayHintEnabled(DraggedHint, true); 00297 00298 emit urlsDropped(m_url, event); 00299 00300 setDisplayHintEnabled(DraggedHint, false); 00301 update(); 00302 } 00303 } 00304 00305 void KUrlNavigatorButton::dragEnterEvent(QDragEnterEvent* event) 00306 { 00307 if (event->mimeData()->hasUrls()) { 00308 setDisplayHintEnabled(DraggedHint, true); 00309 event->acceptProposedAction(); 00310 00311 update(); 00312 } 00313 } 00314 00315 void KUrlNavigatorButton::dragMoveEvent(QDragMoveEvent* event) 00316 { 00317 QRect rect = event->answerRect(); 00318 if (isAboveArrow(rect.center().x())) { 00319 m_hoverArrow = true; 00320 update(); 00321 00322 if (m_subDirsMenu == 0) { 00323 requestSubDirs(); 00324 } else if (m_subDirsMenu->parent() != this) { 00325 m_subDirsMenu->close(); 00326 m_subDirsMenu->deleteLater(); 00327 m_subDirsMenu = 0; 00328 00329 requestSubDirs(); 00330 } 00331 } else { 00332 if (m_openSubDirsTimer->isActive()) { 00333 cancelSubDirsRequest(); 00334 } 00335 delete m_subDirsMenu; 00336 m_subDirsMenu = 0; 00337 m_hoverArrow = false; 00338 update(); 00339 } 00340 } 00341 00342 void KUrlNavigatorButton::dragLeaveEvent(QDragLeaveEvent* event) 00343 { 00344 KUrlNavigatorButtonBase::dragLeaveEvent(event); 00345 00346 m_hoverArrow = false; 00347 setDisplayHintEnabled(DraggedHint, false); 00348 update(); 00349 } 00350 00351 void KUrlNavigatorButton::mousePressEvent(QMouseEvent* event) 00352 { 00353 if (isAboveArrow(event->x()) && (event->button() == Qt::LeftButton)) { 00354 // the mouse is pressed above the [>] button 00355 startSubDirsJob(); 00356 } 00357 KUrlNavigatorButtonBase::mousePressEvent(event); 00358 } 00359 00360 void KUrlNavigatorButton::mouseReleaseEvent(QMouseEvent* event) 00361 { 00362 if (!isAboveArrow(event->x()) || (event->button() != Qt::LeftButton)) { 00363 // the mouse has been released above the text area and not 00364 // above the [>] button 00365 emit clicked(m_url, event->button()); 00366 cancelSubDirsRequest(); 00367 } 00368 KUrlNavigatorButtonBase::mouseReleaseEvent(event); 00369 } 00370 00371 void KUrlNavigatorButton::mouseMoveEvent(QMouseEvent* event) 00372 { 00373 KUrlNavigatorButtonBase::mouseMoveEvent(event); 00374 00375 const bool hoverArrow = isAboveArrow(event->x()); 00376 if (hoverArrow != m_hoverArrow) { 00377 m_hoverArrow = hoverArrow; 00378 update(); 00379 } 00380 } 00381 00382 void KUrlNavigatorButton::wheelEvent(QWheelEvent* event) 00383 { 00384 if (event->orientation() == Qt::Vertical) { 00385 m_wheelSteps = event->delta() / 120; 00386 m_replaceButton = true; 00387 startSubDirsJob(); 00388 } 00389 00390 KUrlNavigatorButtonBase::wheelEvent(event); 00391 } 00392 00393 void KUrlNavigatorButton::requestSubDirs() 00394 { 00395 if (!m_openSubDirsTimer->isActive() && (m_subDirsJob == 0)) { 00396 m_openSubDirsTimer->start(); 00397 } 00398 } 00399 00400 void KUrlNavigatorButton::startSubDirsJob() 00401 { 00402 if (m_subDirsJob != 0) { 00403 return; 00404 } 00405 00406 const KUrl url = m_replaceButton ? m_url.upUrl() : m_url; 00407 m_subDirsJob = KIO::listDir(url, KIO::HideProgressInfo, false /*no hidden files*/); 00408 m_subDirs.clear(); // just to be ++safe 00409 00410 connect(m_subDirsJob, SIGNAL(entries(KIO::Job*, const KIO::UDSEntryList &)), 00411 this, SLOT(addEntriesToSubDirs(KIO::Job*, const KIO::UDSEntryList&))); 00412 00413 if (m_replaceButton) { 00414 connect(m_subDirsJob, SIGNAL(result(KJob*)), this, SLOT(replaceButton(KJob*))); 00415 } else { 00416 connect(m_subDirsJob, SIGNAL(result(KJob*)), this, SLOT(openSubDirsMenu(KJob*))); 00417 } 00418 } 00419 00420 void KUrlNavigatorButton::addEntriesToSubDirs(KIO::Job* job, const KIO::UDSEntryList& entries) 00421 { 00422 Q_ASSERT(job == m_subDirsJob); 00423 Q_UNUSED(job); 00424 00425 foreach (const KIO::UDSEntry& entry, entries) { 00426 if (entry.isDir()) { 00427 const QString name = entry.stringValue(KIO::UDSEntry::UDS_NAME); 00428 QString displayName = entry.stringValue(KIO::UDSEntry::UDS_DISPLAY_NAME); 00429 if (displayName.isEmpty()) { 00430 displayName = name; 00431 } 00432 if ((name != QLatin1String(".")) && (name != QLatin1String(".."))) { 00433 m_subDirs.append(qMakePair(name, displayName)); 00434 } 00435 } 00436 } 00437 } 00438 00439 void KUrlNavigatorButton::urlsDropped(QAction* action, QDropEvent* event) 00440 { 00441 const int result = action->data().toInt(); 00442 KUrl url = m_url; 00443 url.addPath(m_subDirs.at(result).first); 00444 urlsDropped(url, event); 00445 } 00446 00447 void KUrlNavigatorButton::slotMenuActionClicked(QAction* action) 00448 { 00449 const int result = action->data().toInt(); 00450 KUrl url = m_url; 00451 url.addPath(m_subDirs.at(result).first); 00452 emit clicked(url, Qt::MidButton); 00453 } 00454 00455 void KUrlNavigatorButton::statFinished(KJob* job) 00456 { 00457 if (m_pendingTextChange) { 00458 m_pendingTextChange = false; 00459 00460 const KIO::UDSEntry entry = static_cast<KIO::StatJob*>(job)->statResult(); 00461 QString name = entry.stringValue(KIO::UDSEntry::UDS_DISPLAY_NAME); 00462 if (name.isEmpty()) { 00463 name = m_url.fileName(); 00464 } 00465 setText(name); 00466 00467 emit finishedTextResolving(); 00468 } 00469 } 00470 00474 static bool naturalLessThan(const QPair<QString, QString>& s1, const QPair<QString, QString>& s2) 00475 { 00476 return KStringHandler::naturalCompare(s1.first, s2.first, Qt::CaseInsensitive) < 0; 00477 } 00478 00479 void KUrlNavigatorButton::openSubDirsMenu(KJob* job) 00480 { 00481 Q_ASSERT(job == m_subDirsJob); 00482 m_subDirsJob = 0; 00483 00484 if (job->error() || m_subDirs.isEmpty()) { 00485 // clear listing 00486 return; 00487 } 00488 00489 qSort(m_subDirs.begin(), m_subDirs.end(), naturalLessThan); 00490 setDisplayHintEnabled(PopupActiveHint, true); 00491 update(); // ensure the button is drawn highlighted 00492 00493 if (m_subDirsMenu != 0) { 00494 m_subDirsMenu->close(); 00495 m_subDirsMenu->deleteLater(); 00496 m_subDirsMenu = 0; 00497 } 00498 00499 m_subDirsMenu = new KUrlNavigatorMenu(this); 00500 initMenu(m_subDirsMenu, 0); 00501 00502 const bool leftToRight = (layoutDirection() == Qt::LeftToRight); 00503 const int popupX = leftToRight ? width() - arrowWidth() - BorderWidth : 0; 00504 const QPoint popupPos = parentWidget()->mapToGlobal(geometry().bottomLeft() + QPoint(popupX, 0)); 00505 00506 const QAction* action = m_subDirsMenu->exec(popupPos); 00507 if (action != 0) { 00508 const int result = action->data().toInt(); 00509 KUrl url = m_url; 00510 url.addPath(m_subDirs[result].first); 00511 emit clicked(url, Qt::LeftButton); 00512 } 00513 00514 m_subDirs.clear(); 00515 delete m_subDirsMenu; 00516 m_subDirsMenu = 0; 00517 00518 setDisplayHintEnabled(PopupActiveHint, false); 00519 } 00520 00521 void KUrlNavigatorButton::replaceButton(KJob* job) 00522 { 00523 Q_ASSERT(job == m_subDirsJob); 00524 m_subDirsJob = 0; 00525 m_replaceButton = false; 00526 00527 if (job->error() || m_subDirs.isEmpty()) { 00528 return; 00529 } 00530 00531 qSort(m_subDirs.begin(), m_subDirs.end(), naturalLessThan); 00532 00533 // Get index of the directory that is shown currently in the button 00534 const QString currentDir = m_url.fileName(); 00535 int currentIndex = 0; 00536 const int subDirsCount = m_subDirs.count(); 00537 while (currentIndex < subDirsCount) { 00538 if (m_subDirs[currentIndex].first == currentDir) { 00539 break; 00540 } 00541 ++currentIndex; 00542 } 00543 00544 // Adjust the index by respecting the wheel steps and 00545 // trigger a replacing of the button content 00546 int targetIndex = currentIndex - m_wheelSteps; 00547 if (targetIndex < 0) { 00548 targetIndex = 0; 00549 } else if (targetIndex >= subDirsCount) { 00550 targetIndex = subDirsCount - 1; 00551 } 00552 00553 KUrl url = m_url.upUrl(); 00554 url.addPath(m_subDirs[targetIndex].first); 00555 00556 emit clicked(url, Qt::LeftButton); 00557 00558 m_subDirs.clear(); 00559 } 00560 00561 void KUrlNavigatorButton::cancelSubDirsRequest() 00562 { 00563 m_openSubDirsTimer->stop(); 00564 if (m_subDirsJob != 0) { 00565 m_subDirsJob->kill(); 00566 m_subDirsJob = 0; 00567 } 00568 } 00569 00570 QString KUrlNavigatorButton::plainText() const 00571 { 00572 // Replace all "&&" by '&' and remove all single 00573 // '&' characters 00574 const QString source = text(); 00575 const int sourceLength = source.length(); 00576 00577 QString dest; 00578 dest.reserve(sourceLength); 00579 00580 int sourceIndex = 0; 00581 int destIndex = 0; 00582 while (sourceIndex < sourceLength) { 00583 if (source.at(sourceIndex) == QLatin1Char('&')) { 00584 ++sourceIndex; 00585 if (sourceIndex >= sourceLength) { 00586 break; 00587 } 00588 } 00589 dest[destIndex] = source.at(sourceIndex); 00590 ++sourceIndex; 00591 ++destIndex; 00592 } 00593 00594 return dest; 00595 } 00596 00597 int KUrlNavigatorButton::arrowWidth() const 00598 { 00599 // if there isn't arrow then return 0 00600 int width = 0; 00601 if (!m_subDir.isEmpty()) { 00602 width = height() / 2; 00603 if (width < 4) { 00604 width = 4; 00605 } 00606 } 00607 00608 return width; 00609 } 00610 00611 bool KUrlNavigatorButton::isAboveArrow(int x) const 00612 { 00613 const bool leftToRight = (layoutDirection() == Qt::LeftToRight); 00614 return leftToRight ? (x >= width() - arrowWidth()) : (x < arrowWidth()); 00615 } 00616 00617 bool KUrlNavigatorButton::isTextClipped() const 00618 { 00619 int availableWidth = width() - 2 * BorderWidth; 00620 if (!m_subDir.isEmpty()) { 00621 availableWidth -= arrowWidth() - BorderWidth; 00622 } 00623 00624 QFont adjustedFont(font()); 00625 adjustedFont.setBold(m_subDir.isEmpty()); 00626 return QFontMetrics(adjustedFont).width(plainText()) >= availableWidth; 00627 } 00628 00629 void KUrlNavigatorButton::updateMinimumWidth() 00630 { 00631 const int oldMinWidth = minimumWidth(); 00632 00633 int minWidth = sizeHint().width(); 00634 if (minWidth < 40) { 00635 minWidth = 40; 00636 } 00637 else if (minWidth > 150) { 00638 // don't let an overlong path name waste all the URL navigator space 00639 minWidth = 150; 00640 } 00641 if (oldMinWidth != minWidth) { 00642 setMinimumWidth(minWidth); 00643 } 00644 } 00645 00646 void KUrlNavigatorButton::initMenu(KUrlNavigatorMenu* menu, int startIndex) 00647 { 00648 connect(menu, SIGNAL(middleMouseButtonClicked(QAction*)), 00649 this, SLOT(slotMenuActionClicked(QAction*))); 00650 connect(menu, SIGNAL(urlsDropped(QAction*, QDropEvent*)), 00651 this, SLOT(urlsDropped(QAction*, QDropEvent*))); 00652 00653 menu->setLayoutDirection(Qt::LeftToRight); 00654 00655 const int maxIndex = startIndex + 30; // Don't show more than 30 items in a menu 00656 const int lastIndex = qMin(m_subDirs.count() - 1, maxIndex); 00657 for (int i = startIndex; i <= lastIndex; ++i) { 00658 const QString subDirName = m_subDirs[i].first; 00659 const QString subDirDisplayName = m_subDirs[i].second; 00660 QString text = KStringHandler::csqueeze(subDirDisplayName, 60); 00661 text.replace(QLatin1Char('&'), QLatin1String("&&")); 00662 QAction* action = new QAction(text, this); 00663 if (m_subDir == subDirName) { 00664 QFont font(action->font()); 00665 font.setBold(true); 00666 action->setFont(font); 00667 } 00668 action->setData(i); 00669 menu->addAction(action); 00670 } 00671 if (m_subDirs.count() > maxIndex) { 00672 // If too much items are shown, move them into a sub menu 00673 menu->addSeparator(); 00674 KUrlNavigatorMenu* subDirsMenu = new KUrlNavigatorMenu(menu); 00675 subDirsMenu->setTitle(i18nc("@action:inmenu", "More")); 00676 initMenu(subDirsMenu, maxIndex); 00677 menu->addMenu(subDirsMenu); 00678 } 00679 } 00680 00681 } // namespace KDEPrivate 00682 00683 #include "kurlnavigatorbutton_p.moc"
KDE 4.7 API Reference