void Archive::loadExtractedBaskets(const QString &extractionFolder, QDomNode &basketNode, QMap<QString, QString> &folderMap, Basket *parent) { bool basketSetAsCurrent = (parent != 0); QDomNode n = basketNode; while ( ! n.isNull() ) { QDomElement element = n.toElement(); if ( (!element.isNull()) && element.tagName() == "basket" ) { QString folderName = element.attribute("folderName"); if (!folderName.isEmpty()) { // Move the basket folder to its destination, while renaming it uniquely: QString newFolderName = folderMap[folderName]; FormatImporter copier; // The folder has been "reserved" by creating it. Avoid asking the user to override: QDir dir; dir.rmdir(Global::basketsFolder() + newFolderName); copier.moveFolder(extractionFolder + "baskets/" + folderName, Global::basketsFolder() + newFolderName); // Append and load the basket in the tree: Basket *basket = Global::bnpView->loadBasket(newFolderName); BasketListViewItem *basketItem = Global::bnpView->appendBasket(basket, (basket && parent ? Global::bnpView->listViewItemForBasket(parent) : 0)); basketItem->setExpanded(!XMLWork::trueOrFalse(element.attribute("folded", "false"), false)); QDomElement properties = XMLWork::getElement(element, "properties"); importBasketIcon(properties, extractionFolder); // Rename the icon fileName if necessary basket->loadProperties(properties); // Open the first basket of the archive: if (!basketSetAsCurrent) { Global::bnpView->setCurrentBasket(basket); basketSetAsCurrent = true; } QDomNode node = element.firstChild(); loadExtractedBaskets(extractionFolder, node, folderMap, basket); } } n = n.nextSibling(); } }
void HTMLExporter::prepareExport(Basket *basket, const QString &fullPath) { progress->setRange(0,/*Preparation:*/1 + /*Finishing:*/1 + /*Basket:*/1 + /*SubBaskets:*/Global::bnpView->basketCount(Global::bnpView->listViewItemForBasket(basket))); progress->setValue(0); kapp->processEvents(); // Remember the file path choosen by the user: filePath = fullPath; fileName = KUrl(fullPath).fileName(); exportedBasket = basket; BasketListViewItem *item = Global::bnpView->listViewItemForBasket(basket); withBasketTree = (item->childCount() >= 0); // Create and empty the files folder: QString filesFolderPath = i18nc("HTML export folder (files)", "%1_files", filePath) + "/"; // eg.: "/home/seb/foo.html_files/" Tools::deleteRecursively(filesFolderPath); QDir dir; dir.mkdir(filesFolderPath); // Create sub-folders: iconsFolderPath = filesFolderPath + i18nc("HTML export folder (icons)", "icons") + "/"; // eg.: "/home/seb/foo.html_files/icons/" imagesFolderPath = filesFolderPath + i18nc("HTML export folder (images)", "images") + "/"; // eg.: "/home/seb/foo.html_files/images/" basketsFolderPath = filesFolderPath + i18nc("HTML export folder (baskets)", "baskets") + "/"; // eg.: "/home/seb/foo.html_files/baskets/" dir.mkdir(iconsFolderPath); dir.mkdir(imagesFolderPath); dir.mkdir(basketsFolderPath); progress->setValue(progress->value()+1); // Preparation finished }
void BasketListViewItem::ensureVisible() { BasketListViewItem *item = this; while (item->parent()) { item = (BasketListViewItem*)(item->parent()); item->setExpanded(true); } }
void Archive::listUsedTags(Basket *basket, bool recursive, QList<Tag*> &list) { basket->listUsedTags(list); BasketListViewItem *item = Global::bnpView->listViewItemForBasket(basket); if (recursive) { for (int i=0;i<item->childCount();i++){ listUsedTags(((BasketListViewItem *)item->child(i))->basket(), recursive, list); } } }
int BasketListViewItem::countChildsFound() { int count = 0; for (int i = 0; i < childCount(); i++) { BasketListViewItem *childItem = (BasketListViewItem*)child(i); count += childItem->basket()->countFounds(); count += childItem->countChildsFound(); } return count; }
CrossReferenceEditDialog::CrossReferenceEditDialog(CrossReferenceContent *contentNote, QWidget *parent/*, QKeyEvent *ke*/) : KDialog(parent) , m_noteContent(contentNote) { // KDialog options setCaption(i18n("Edit Cross Reference")); setButtons(Ok | Cancel); setDefaultButton(Ok); setObjectName("EditCrossReference"); setModal(true); showButtonSeparator(true); connect(this, SIGNAL(okClicked()), SLOT(slotOk())); QWidget *page = new QWidget(this); setMainWidget(page); QWidget *wid = new QWidget(page); QGridLayout *layout = new QGridLayout(page); m_targetBasket = new KComboBox(wid); this->generateBasketList(m_targetBasket); if(m_noteContent->url().isEmpty()){ BasketListViewItem *item = Global::bnpView->topLevelItem(0); m_noteContent->setCrossReference(KUrl(item->data(0, Qt::UserRole).toString()), m_targetBasket->currentText(), "edit-copy"); this->urlChanged(0); } else { QString url = m_noteContent->url().url(); //cannot use findData because I'm using a StringList and I don't have the second // piece of data to make find work. for(int i = 0; i < m_targetBasket->count(); ++i) { if(url == m_targetBasket->itemData(i, Qt::UserRole).toStringList().first()) { m_targetBasket->setCurrentIndex(i); break; } } } QLabel *label1 = new QLabel(page); label1->setText(i18n("Ta&rget:")); label1->setBuddy(m_targetBasket); layout->addWidget(label1, 0, 0, Qt::AlignVCenter); layout->addWidget(m_targetBasket, 0, 1, Qt::AlignVCenter); connect(m_targetBasket, SIGNAL(activated(int)), this, SLOT(urlChanged(int))); QWidget *stretchWidget = new QWidget(page); QSizePolicy policy(QSizePolicy::Fixed, QSizePolicy::Expanding); policy.setHorizontalStretch(1); policy.setVerticalStretch(255); stretchWidget->setSizePolicy(policy); // Make it fill ALL vertical space layout->addWidget(stretchWidget, 3, 1, Qt::AlignVCenter); }
bool BasketListViewItem::haveChildsLocked() { for (int i = 0; i < childCount(); i++) { BasketListViewItem *childItem = (BasketListViewItem*)child(i); if (/*!*/childItem->basket()->isLocked()) return true; if (childItem->haveChildsLocked()) return true; } return false; }
void Archive::saveBasketToArchive(Basket *basket, bool recursive, KTar *tar, QStringList &backgrounds, const QString &tempFolder, QProgressBar *progress) { // Basket need to be loaded for tags exportation. // We load it NOW so that the progress bar really reflect the state of the exportation: if (!basket->isLoaded()) { basket->load(); } QDir dir; // Save basket data: tar->addLocalDirectory(basket->fullPath(), "baskets/" + basket->folderName()); tar->addLocalFile(basket->fullPath() + ".basket", "baskets/" + basket->folderName() + ".basket"); // The hidden files were not added // Save basket icon: QString tempIconFile = tempFolder + "icon.png"; if (!basket->icon().isEmpty() && basket->icon() != "basket") { QPixmap icon = KIconLoader::global()->loadIcon(basket->icon(), KIconLoader::Small, 16, KIconLoader::DefaultState, QStringList(), /*path_store=*/0L, /*canReturnNull=*/true); if (!icon.isNull()) { icon.save(tempIconFile, "PNG"); QString iconFileName = basket->icon().replace('/', '_'); tar->addLocalFile(tempIconFile, "basket-icons/" + iconFileName); } } // Save basket backgorund image: QString imageName = basket->backgroundImageName(); if (!basket->backgroundImageName().isEmpty() && !backgrounds.contains(imageName)) { QString backgroundPath = Global::backgroundManager->pathForImageName(imageName); if (!backgroundPath.isEmpty()) { // Save the background image: tar->addLocalFile(backgroundPath, "backgrounds/" + imageName); // Save the preview image: QString previewPath = Global::backgroundManager->previewPathForImageName(imageName); if (!previewPath.isEmpty()) tar->addLocalFile(previewPath, "backgrounds/previews/" + imageName); // Save the configuration file: QString configPath = backgroundPath + ".config"; if (dir.exists(configPath)) tar->addLocalFile(configPath, "backgrounds/" + imageName + ".config"); } backgrounds.append(imageName); } progress->setValue(progress->value()+1); // Basket exportation finished kDebug() << basket->basketName() << " finished"; // Recursively save child baskets: BasketListViewItem *item = Global::bnpView->listViewItemForBasket(basket); if (recursive) { for (int i=0;i<item->childCount();i++){ saveBasketToArchive(((BasketListViewItem *)item->child(i))->basket(), recursive, tar, backgrounds, tempFolder, progress); } } }
bool BasketTreeListView::event(QEvent *e) { if (e->type() == QEvent::ToolTip) { QHelpEvent *he = static_cast<QHelpEvent *>(e); QTreeWidgetItem *item = itemAt(he->pos()); BasketListViewItem* bitem = dynamic_cast<BasketListViewItem*>(item); if (bitem && bitem->isAbbreviated()) { QRect rect = visualItemRect(bitem); QToolTip::showText(rect.topLeft(), bitem->basket()->basketName(), viewport(), rect); } return true; } return QTreeWidget::event(e); }
void HTMLExporter::writeBasketTree(Basket *currentBasket, Basket *basket, int indent) { // Compute variable HTML code: QString spaces; QString cssClass = (basket == currentBasket ? " class=\"current\"" : ""); QString link = "#"; if (currentBasket != basket) { if (currentBasket == exportedBasket) { link = basketsFolderName + basket->folderName().left(basket->folderName().length() - 1) + ".html"; } else if (basket == exportedBasket) { link = "../../" + fileName; } else { link = basket->folderName().left(basket->folderName().length() - 1) + ".html"; } } QString spanStyle = ""; if (basket->backgroundColorSetting().isValid() || basket->textColorSetting().isValid()) { spanStyle = " style=\"background-color: " + basket->backgroundColor().name() + "; color: " + basket->textColor().name() + "\""; } // Write the basket tree line: stream << spaces.fill(' ', indent) << "<li><a" << cssClass << " href=\"" << link << "\">" "<span" << spanStyle << " title=\"" << Tools::textToHTMLWithoutP(basket->basketName()) << "\">" "<img src=\"" << iconsFolderName << copyIcon(basket->icon(), 16) << "\" width=\"16\" height=\"16\" alt=\"\">" << Tools::textToHTMLWithoutP(basket->basketName()) << "</span></a>"; // Write the sub-baskets lines & end the current one: BasketListViewItem *item = Global::bnpView->listViewItemForBasket(basket); if (item->childCount() >= 0) { stream << "\n" << spaces.fill(' ', indent) << " <ul>\n"; for (int i=0; i<item->childCount(); i++) writeBasketTree(currentBasket, ((BasketListViewItem*)item->child(i))->basket(), indent + 2); stream << spaces.fill(' ', indent) << " </ul>\n" << spaces.fill(' ', indent) << "</li>\n"; } else { stream << "</li>\n"; } }
QMimeData* BasketTreeListView::mimeData(const QList<QTreeWidgetItem *> items) const { QString mimeType = TREE_ITEM_MIME_STRING; QByteArray data = QByteArray(); QDataStream out(&data, QIODevice::WriteOnly); if(items.isEmpty()) return new QMimeData(); for (int i = 0; i < items.count(); ++i) { BasketListViewItem *basketItem = static_cast<BasketListViewItem*>(items[i]); out << basketItem->basket()->basketName() << basketItem->basket()->folderName() << basketItem->basket()->icon(); } QMimeData *mimeData = new QMimeData(); mimeData->setData(mimeType, data); return mimeData; }
void BasketTreeListView::dropEvent(QDropEvent *event) { if (event->mimeData()->hasFormat(TREE_ITEM_MIME_STRING)) { event->setDropAction(Qt::MoveAction); QTreeWidget::dropEvent(event); } else { // this handels application/x-basket-note drag events. kDebug() << "Forwarding dropped data to the basket"; event->setDropAction(Qt::MoveAction); QTreeWidgetItem *item = itemAt(event->pos()); BasketListViewItem* bitem = dynamic_cast<BasketListViewItem*>(item); if (bitem) { bitem->basket()->blindDrop(event->mimeData(),event->dropAction(),event->source()); } else { kDebug() << "Forwarding failed: no bitem found"; } } m_autoOpenItem = 0; m_autoOpenTimer.stop(); setItemUnderDrag(0); removeExpands(); Global::bnpView->save(); // TODO: Don't save if it was not a basket drop... }
void HTMLExporter::exportBasket(Basket *basket, bool isSubBasket) { if (!basket->isLoaded()) { basket->load(); } // Compute the absolute & relative paths for this basket: filesFolderPath = i18nc("HTML export folder (files)", "%1_files", filePath) + "/"; if (isSubBasket) { basketFilePath = basketsFolderPath + basket->folderName().left(basket->folderName().length() - 1) + ".html"; filesFolderName = "../"; dataFolderName = basket->folderName().left(basket->folderName().length() - 1) + "-" + i18nc("HTML export folder (data)", "data") + "/"; dataFolderPath = basketsFolderPath + dataFolderName; basketsFolderName = ""; } else { basketFilePath = filePath; filesFolderName = i18nc("HTML export folder (files)", "%1_files", KUrl(filePath).fileName()) + "/"; dataFolderName = filesFolderName + i18nc("HTML export folder (data)", "data") + "/"; dataFolderPath = filesFolderPath + i18nc("HTML export folder (data)", "data") + "/"; basketsFolderName = filesFolderName + i18nc("HTML export folder (baskets)", "baskets") + "/"; } iconsFolderName = (isSubBasket ? "../" : filesFolderName) + i18nc("HTML export folder (icons)", "icons") + "/"; // eg.: "foo.html_files/icons/" or "../icons/" imagesFolderName = (isSubBasket ? "../" : filesFolderName) + i18nc("HTML export folder (images)", "images") + "/"; // eg.: "foo.html_files/images/" or "../images/" kDebug() << "Exporting ================================================"; kDebug() << " filePath:" << filePath; kDebug() << " basketFilePath:" << basketFilePath; kDebug() << " filesFolderPath:" << filesFolderPath; kDebug() << " filesFolderName:" << filesFolderName; kDebug() << " iconsFolderPath:" << iconsFolderPath; kDebug() << " iconsFolderName:" << iconsFolderName; kDebug() << " imagesFolderPath:" << imagesFolderPath; kDebug() << " imagesFolderName:" << imagesFolderName; kDebug() << " dataFolderPath:" << dataFolderPath; kDebug() << " dataFolderName:" << dataFolderName; kDebug() << " basketsFolderPath:" << basketsFolderPath; kDebug() << " basketsFolderName:" << basketsFolderName; // Create the data folder for this basket: QDir dir; dir.mkdir(dataFolderPath); backgroundColorName = basket->backgroundColor().name().toLower().mid(1); // Generate basket icons: QString basketIcon16 = iconsFolderName + copyIcon(basket->icon(), 16); QString basketIcon32 = iconsFolderName + copyIcon(basket->icon(), 32); // Generate the [+] image for groups: QPixmap expandGroup(Note::EXPANDER_WIDTH, Note::EXPANDER_HEIGHT); expandGroup.fill(basket->backgroundColor()); QPainter painter(&expandGroup); Note::drawExpander(&painter, 0, 0, basket->backgroundColor(), /*expand=*/true, basket); painter.end(); expandGroup.save(imagesFolderPath + "expand_group_" + backgroundColorName + ".png", "PNG"); // Generate the [-] image for groups: QPixmap foldGroup(Note::EXPANDER_WIDTH, Note::EXPANDER_HEIGHT); foldGroup.fill(basket->backgroundColor()); painter.begin(&foldGroup); Note::drawExpander(&painter, 0, 0, basket->backgroundColor(), /*expand=*/false, basket); painter.end(); foldGroup.save(imagesFolderPath + "fold_group_" + backgroundColorName + ".png", "PNG"); // Open the file to write: QFile file(basketFilePath); if (!file.open(QIODevice::WriteOnly)) return; stream.setDevice(&file); stream.setCodec("UTF-8"); // Compute the colors to draw dragient for notes: QColor topBgColor; QColor bottomBgColor; Note::getGradientColors(basket->backgroundColor(), &topBgColor, &bottomBgColor); // Compute the gradient image for notes: QString gradientImageFileName = Basket::saveGradientBackground(basket->backgroundColor(), basket->Q3ScrollView::font(), imagesFolderPath); // Output the header: QString borderColor = Tools::mixColor(basket->backgroundColor(), basket->textColor()).name(); stream << "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\">\n" "<html>\n" " <head>\n" " <meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">\n" " <meta name=\"Generator\" content=\"" << KGlobal::mainComponent().aboutData()->programName() << " " << VERSION << " http://basket.kde.org/\">\n" " <style type=\"text/css\">\n" // " @media print {\n" // " span.printable { display: inline; }\n" // " }\n" " body { margin: 10px; font: 11px sans-serif; }\n" // TODO: Use user font " h1 { text-align: center; }\n" " img { border: none; vertical-align: middle; }\n"; if (withBasketTree) { stream << " .tree { margin: 0; padding: 1px 0 1px 1px; width: 150px; _width: 149px; overflow: hidden; float: left; }\n" " .tree ul { margin: 0 0 0 10px; padding: 0; }\n" " .tree li { padding: 0; margin: 0; list-style: none; }\n" " .tree a { display: block; padding: 1px; height: 16px; text-decoration: none;\n" " white-space: nowrap; word-wrap: normal; text-wrap: suppress; color: black; }\n" " .tree span { -moz-border-radius: 6px; display: block; float: left;\n" " line-height: 16px; height: 16px; vertical-align: middle; padding: 0 1px; }\n" " .tree img { vertical-align: top; padding-right: 1px; }\n" " .tree .current { background-color: " << kapp->palette().color(QPalette::Highlight).name() << "; " "-moz-border-radius: 3px 0 0 3px; border-radius: 3px 0 0 3px; color: " << kapp->palette().color(QPalette::Highlight).name() << "; }\n" " .basketSurrounder { margin-left: 152px; _margin: 0; _float: right; }\n"; } stream << " .basket { background-color: " << basket->backgroundColor().name() << "; border: solid " << borderColor << " 1px; " "font: " << Tools::cssFontDefinition(basket->Q3ScrollView::font()) << "; color: " << basket->textColor().name() << "; padding: 1px; width: 100%; }\n" " table.basket { border-collapse: collapse; }\n" " .basket * { padding: 0; margin: 0; }\n" " .basket table { width: 100%; border-spacing: 0; _border-collapse: collapse; }\n" " .column { vertical-align: top; }\n" " .columnHandle { width: " << Note::RESIZER_WIDTH << "px; background: transparent url('" << imagesFolderName << "column_handle_" << backgroundColorName << ".png') repeat-y; }\n" " .group { margin: 0; padding: 0; border-collapse: collapse; width: 100% }\n" " .groupHandle { margin: 0; width: " << Note::GROUP_WIDTH << "px; text-align: center; }\n" " .note { padding: 1px 2px; background: " << bottomBgColor.name() << " url('" << imagesFolderName << gradientImageFileName << "')" " repeat-x; border-top: solid " << topBgColor.name() << " 1px; border-bottom: solid " << Tools::mixColor(topBgColor, bottomBgColor).name() << " 1px; width: 100%; }\n" " .tags { width: 1px; white-space: nowrap; }\n" " .tags img { padding-right: 2px; }\n" << LinkLook::soundLook->toCSS("sound", basket->textColor()) << LinkLook::fileLook->toCSS("file", basket->textColor()) << LinkLook::localLinkLook->toCSS("local", basket->textColor()) << LinkLook::networkLinkLook->toCSS("network", basket->textColor()) << LinkLook::launcherLook->toCSS("launcher", basket->textColor()) << " .unknown { margin: 1px 2px; border: 1px solid " << borderColor << "; -moz-border-radius: 4px; }\n"; QList<State*> states = basket->usedStates(); QString statesCss; for (State::List::Iterator it = states.begin(); it != states.end(); ++it) statesCss += (*it)->toCSS(imagesFolderPath, imagesFolderName, basket->Q3ScrollView::font()); stream << statesCss << " .credits { text-align: right; margin: 3px 0 0 0; _margin-top: -17px; font-size: 80%; color: " << borderColor << "; }\n" " </style>\n" " <title>" << Tools::textToHTMLWithoutP(basket->basketName()) << "</title>\n" " <link rel=\"shortcut icon\" type=\"image/png\" href=\"" << basketIcon16 << "\">\n"; // Create the column handle image: QPixmap columnHandle(Note::RESIZER_WIDTH, 50); painter.begin(&columnHandle); Note::drawInactiveResizer(&painter, 0, 0, columnHandle.height(), basket->backgroundColor(), /*column=*/true); painter.end(); columnHandle.save(imagesFolderPath + "column_handle_" + backgroundColorName + ".png", "PNG"); stream << " </head>\n" " <body>\n" " <h1><img src=\"" << basketIcon32 << "\" width=\"32\" height=\"32\" alt=\"\"> " << Tools::textToHTMLWithoutP(basket->basketName()) << "</h1>\n"; if (withBasketTree) writeBasketTree(basket); // If filtering, only export filtered notes, inform to the user: // TODO: Filtering tags too!! // TODO: Make sure only filtered notes are exported! // if (decoration()->filterData().isFiltering) // stream << // " <p>" << i18n("Notes matching the filter "%1":").arg(Tools::textToHTMLWithoutP(decoration()->filterData().string)) << "</p>\n"; stream << " <div class=\"basketSurrounder\">\n"; if (basket->isColumnsLayout()) stream << " <table class=\"basket\">\n" " <tr>\n"; else stream << " <div class=\"basket\" style=\"position: relative; height: " << basket->contentsHeight() << "px; width: " << basket->contentsWidth() << "px; min-width: 100%;\">\n"; for (Note *note = basket->firstNote(); note; note = note->next()) exportNote(note, /*indent=*/(basket->isFreeLayout() ? 4 : 5)); // Output the footer: if (basket->isColumnsLayout()) stream << " </tr>\n" " </table>\n"; else stream << " </div>\n"; stream << QString( " </div>\n" " <p class=\"credits\">%1</p>\n").arg( i18n("Made with <a href=\"http://basket.kde.org/\">%1</a> %2, a KDE tool to take notes and keep information at hand.", KGlobal::mainComponent().aboutData()->programName(), VERSION)); // Copy a transparent GIF image in the folder, needed for the JavaScript hack: QString gifFileName = "spacer.gif"; QFile transGIF(imagesFolderPath + gifFileName); if (!transGIF.exists() && transGIF.open(QIODevice::WriteOnly)) { QDataStream streamGIF(&transGIF); // This is a 1px*1px transparent GIF image: const char blankGIF[] = { 0x47, 0x49, 0x46, 0x38, 0x39, 0x61, 0x0a, 0x00, 0x0a, 0x00, 0x80, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x21, 0xfe, 0x15, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x20, 0x77, 0x69, 0x74, 0x68, 0x20, 0x54, 0x68, 0x65, 0x20, 0x47, 0x49, 0x4d, 0x50, 0x00, 0x21, 0xf9, 0x04, 0x01, 0x0a, 0x00, 0x01, 0x00, 0x2c, 0x00, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x0a, 0x00, 0x00, 0x02, 0x08, 0x8c, 0x8f, 0xa9, 0xcb, 0xed, 0x0f, 0x63, 0x2b, 0x00, 0x3b }; streamGIF.writeRawData(blankGIF, 74); transGIF.close(); } stream << " <!--[if lt IE 7]>\n" " <script>\n" " function fixPng(img) {\n" " if (!img.style.filter) {\n" " img.style.filter = \"progid:DXImageTransform.Microsoft.AlphaImageLoader(src='\" + img.src + \"')\";\n" " img.src = \"" << imagesFolderName << gifFileName << "\";\n" " }\n" " }\n" " for (i = document.images.length - 1; i >= 0; i -= 1) {\n" " var img = document.images[i];\n" " if (img.src.substr(img.src.length - 4) == \".png\")\n" " if (img.complete)\n" " fixPng(img);\n" " else\n" " img.attachEvent(\"onload\", function() { fixPng(window.event.srcElement); });\n" " }\n" " </script>\n" " <![endif]-->\n" " </body>\n" "</html>\n"; file.close(); stream.setDevice(0); progress->setValue(progress->value()+1); // Basket exportation finished // Recursively export child baskets: BasketListViewItem *item = Global::bnpView->listViewItemForBasket(basket); if (item->childCount() >=0) { for (int i=0; i < item->childCount(); i++) { exportBasket(((BasketListViewItem *)item->child(i))->basket(), /*isSubBasket=*/true); } } }
void FoundCountIcon::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const { QStyledItemDelegate::paint(painter, option, index); // Get access to basket pointer BasketListViewItem* basketInTree = m_basketTree->getBasketInTree(index); if (basketInTree == NULL) return; const int BASKET_ICON_SIZE = 16; // [replace with m_basketTree->iconSize()] const int MARGIN = 1; BasketScene* basket = basketInTree->basket(); // If we are filtering all baskets, and are effectively filtering on something: bool showLoadingIcon = false; bool showEncryptedIcon = false; QPixmap countPixmap; bool showCountPixmap = Global::bnpView->isFilteringAllBaskets() && Global::bnpView->currentBasket()->decoration()->filterBar()->filterData().isFiltering; if (showCountPixmap) { showLoadingIcon = (!basket->isLoaded() && !basket->isLocked()) || basketInTree->haveHiddenChildsLoading(); showEncryptedIcon = basket->isLocked() || basketInTree->haveHiddenChildsLocked(); bool childrenAreLoading = basketInTree->haveHiddenChildsLoading() || basketInTree->haveHiddenChildsLocked(); countPixmap = foundCountPixmap(!basket->isLoaded(), basket->countFounds(), childrenAreLoading, basketInTree->countHiddenChildsFound(), m_basketTree->font(), option.rect.height() - 2 * MARGIN); } int effectiveWidth = option.rect.right() - (countPixmap.isNull() ? 0 : countPixmap.width() + MARGIN) - (showLoadingIcon || showEncryptedIcon ? BASKET_ICON_SIZE + MARGIN : 0); bool drawRoundRect = basket->backgroundColorSetting().isValid() || basket->textColorSetting().isValid(); // Draw the rounded rectangle: if (drawRoundRect) { QPixmap roundRectBmp; QColor background = basket->backgroundColor(); int textWidth = m_basketTree->fontMetrics().width(basketInTree->text(/*column=*/0)); int iconTextMargin = m_basketTree->style()->pixelMetric(QStyle::PM_FocusFrameHMargin); ///< Space between icon and text // Don't forget to update the key computation if parameters // affecting the rendering logic change QString key = QString("BLIRR::%1.%2.%3.%4") .arg(option.rect.width()) .arg(option.rect.size().height()) .arg(textWidth) .arg(background.rgb()); if (QPixmap* cached = QPixmapCache::find(key)) { // Qt's documentation recommends copying the pointer // into a QPixmap immediately roundRectBmp = *cached; } else { // Draw first time roundRectBmp = QPixmap(option.rect.size()); roundRectBmp.fill(Qt::transparent); QPainter brushPainter(&roundRectBmp); int cornerR = option.rect.height()/2 - MARGIN; QRect roundRect(0, MARGIN, BASKET_ICON_SIZE + iconTextMargin + textWidth + 2*cornerR, option.rect.height() - 2*MARGIN); brushPainter.setPen(background); brushPainter.setBrush(background); brushPainter.setRenderHint(QPainter::Antialiasing); brushPainter.drawRoundedRect(roundRect, cornerR, cornerR); QPixmapCache::insert(key, roundRectBmp); } basketInTree->setBackground(0, QBrush(roundRectBmp)); basketInTree->setForeground(0, QBrush(basket->textColor())); } //end if drawRoundRect // Render icons on the right int y = option.rect.center().y() - BASKET_ICON_SIZE/2; if (!countPixmap.isNull()) { painter->drawPixmap(effectiveWidth, y, countPixmap); effectiveWidth += countPixmap.width() + MARGIN; } if (showLoadingIcon) { QPixmap icon = KIconLoader::global()->loadIcon(IconNames::LOADING, KIconLoader::NoGroup, BASKET_ICON_SIZE); painter->drawPixmap(effectiveWidth, y, icon); effectiveWidth += BASKET_ICON_SIZE + MARGIN; } if (showEncryptedIcon && !showLoadingIcon) { QPixmap icon = KIconLoader::global()->loadIcon(IconNames::LOCKED, KIconLoader::NoGroup, BASKET_ICON_SIZE); painter->drawPixmap(effectiveWidth, y, icon); } }
void BasketTreeListView::autoOpen() { BasketListViewItem *item = (BasketListViewItem*)m_autoOpenItem; if (item) Global::bnpView->setCurrentBasket(item->basket()); }