diff --git a/smb4k/CMakeLists.txt b/smb4k/CMakeLists.txt index c9bf3a9..49af27d 100644 --- a/smb4k/CMakeLists.txt +++ b/smb4k/CMakeLists.txt @@ -1,87 +1,86 @@ include_directories( ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/configdlg ${CMAKE_CURRENT_BINARY_DIR}/configdlg ${CMAKE_SOURCE_DIR}/core ${CMAKE_BINARY_DIR}/core ${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR}) add_subdirectory(icons) ########### Configuration dialog ##################### set(smb4kconfigdialog_LIB_SRCS smb4kconfigdialog.cpp smb4kconfigpageauthentication.cpp smb4kconfigpagecustomoptions.cpp smb4kconfigpagemounting.cpp smb4kconfigpagenetwork.cpp smb4kconfigpageprofiles.cpp smb4kconfigpagesynchronization.cpp smb4kconfigpageuserinterface.cpp) add_library(smb4kconfigdialog MODULE ${smb4kconfigdialog_LIB_SRCS}) target_link_libraries(smb4kconfigdialog Qt5::Core Qt5::Widgets Qt5::Gui KF5::WidgetsAddons KF5::CoreAddons KF5::XmlGui KF5::IconThemes KF5::I18n KF5::ConfigCore KF5::ConfigGui KF5::KIOCore KF5::KIOWidgets smb4kcore) ########### Main Application ######################### set(smb4k_SRCS main.cpp smb4kbookmarkmenu.cpp smb4kprofilesmenu.cpp smb4kmainwindow.cpp smb4knetworkbrowser.cpp smb4knetworkbrowseritem.cpp smb4knetworkbrowserdockwidget.cpp smb4knetworksearchtoolbar.cpp smb4ksharesmenu.cpp smb4ksharesview.cpp smb4ksharesviewitem.cpp smb4ksharesviewdockwidget.cpp - smb4ksystemtray.cpp - smb4ktooltip.cpp) + smb4ksystemtray.cpp) add_executable(smb4k ${smb4k_SRCS}) target_link_libraries(smb4k smb4kcore Qt5::Core Qt5::Gui Qt5::Widgets KF5::CoreAddons KF5::WidgetsAddons KF5::DBusAddons KF5::XmlGui KF5::I18n KF5::IconThemes KF5::KIOCore KF5::ConfigWidgets KF5::Crash KF5::WindowSystem) ########### install files ############### install(TARGETS smb4kconfigdialog DESTINATION ${KDE_INSTALL_PLUGINDIR}) install(TARGETS smb4k DESTINATION ${KDE_INSTALL_BINDIR}) install(PROGRAMS org.kde.smb4k.desktop DESTINATION ${XDG_APPS_INSTALL_DIR}) install(FILES smb4k_shell.rc DESTINATION ${KDE_INSTALL_KXMLGUI5DIR}/smb4k) install(FILES org.kde.smb4k.appdata.xml DESTINATION ${KDE_INSTALL_METAINFODIR}) diff --git a/smb4k/smb4knetworkbrowser.cpp b/smb4k/smb4knetworkbrowser.cpp index 1ed5a17..55e7565 100644 --- a/smb4k/smb4knetworkbrowser.cpp +++ b/smb4k/smb4knetworkbrowser.cpp @@ -1,377 +1,244 @@ /*************************************************************************** smb4knetworkbrowser - The network browser widget of Smb4K. ------------------- begin : Mo Jan 8 2007 - copyright : (C) 2007-2019 by Alexander Reinholdt + copyright : (C) 2007-2020 by Alexander Reinholdt email : alexander.reinholdt@kdemail.net ***************************************************************************/ /*************************************************************************** * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, but * * WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * * General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., 51 Franklin Street, Suite 500, Boston,* * MA 02110-1335, USA * ***************************************************************************/ // application specific includes #include "smb4knetworkbrowser.h" #include "smb4knetworkbrowseritem.h" -#include "smb4ktooltip.h" #include "core/smb4ksettings.h" #include "core/smb4kglobal.h" #include "core/smb4kshare.h" // Qt includes #include #include -#include -#include -#include -#include #include -#include #include +#include +#include +#include // KDE includes #include using namespace Smb4KGlobal; Smb4KNetworkBrowser::Smb4KNetworkBrowser(QWidget *parent) : QTreeWidget(parent) { setRootIsDecorated(true); setAllColumnsShowFocus(false); setMouseTracking(true); setSelectionMode(ExtendedSelection); setContextMenuPolicy(Qt::CustomContextMenu); - - m_tooltip_item = 0; - m_mouse_inside = false; + + m_toolTip = new KToolTipWidget(this); QStringList header_labels; header_labels.append(i18n("Network")); header_labels.append(i18n("Type")); header_labels.append(i18n("IP Address")); header_labels.append(i18n("Comment")); setHeaderLabels(header_labels); header()->setSectionResizeMode(QHeaderView::ResizeToContents); // // Connections // connect(this, SIGNAL(itemActivated(QTreeWidgetItem*,int)), this, SLOT(slotItemActivated(QTreeWidgetItem*,int))); - connect(this, SIGNAL(itemEntered(QTreeWidgetItem*,int)), this, SLOT(slotItemEntered(QTreeWidgetItem*,int))); - connect(this, SIGNAL(viewportEntered()), this, SLOT(slotViewportEntered())); connect(this, SIGNAL(itemSelectionChanged()), this, SLOT(slotItemSelectionChanged())); } Smb4KNetworkBrowser::~Smb4KNetworkBrowser() { } bool Smb4KNetworkBrowser::event(QEvent *e) { switch (e->type()) { case QEvent::ToolTip: { // Intercept the tool tip event and show our own tool tip. QPoint pos = viewport()->mapFromGlobal(cursor().pos()); Smb4KNetworkBrowserItem *item = static_cast(itemAt(pos)); if (item) { if (Smb4KSettings::showNetworkItemToolTip()) { int ind = 0; switch (item->type()) { case Host: { ind = 2; break; } case Share: { ind = 3; break; } default: { ind = 1; break; } } // Check that the tooltip is not over the root decoration. // If it is, hide it. - if (pos.x() <= ind * indentation()) + if (pos.x() > ind * indentation()) { - if (m_tooltip_item) + QPoint tooltipPos = cursor().pos(); + + int testWidth = item->toolTipContentsWidget()->width() + cursor().pos().x() + m_toolTip->layout()->contentsMargins().left() + m_toolTip->layout()->contentsMargins().right(); + + if (QApplication::screenAt(pos)->virtualSize().width() < testWidth) { - emit aboutToHideToolTip(m_tooltip_item); - m_tooltip_item->tooltip()->hide(); - m_tooltip_item = 0; + tooltipPos.setX(cursor().pos().x() - item->toolTipContentsWidget()->width() - m_toolTip->layout()->contentsMargins().left() - m_toolTip->layout()->contentsMargins().right()); } - } - else - { - m_tooltip_item = item; - emit aboutToShowToolTip(m_tooltip_item); - m_tooltip_item->tooltip()->show(cursor().pos()); - } - } - else - { - if (m_tooltip_item) - { - emit aboutToHideToolTip(m_tooltip_item); - m_tooltip_item->tooltip()->hide(); - m_tooltip_item = 0; + + int testHeight = item->toolTipContentsWidget()->height() + cursor().pos().y() + m_toolTip->layout()->contentsMargins().top() + m_toolTip->layout()->contentsMargins().bottom(); + + if (QApplication::screenAt(pos)->virtualSize().height() < testHeight) + { + tooltipPos.setY(cursor().pos().y() - item->toolTipContentsWidget()->height() - m_toolTip->layout()->contentsMargins().top() - m_toolTip->layout()->contentsMargins().bottom()); + } + + m_toolTip->showAt(tooltipPos, item->toolTipContentsWidget(), nativeParentWidget()->windowHandle()); } } } - else - { - if (m_tooltip_item) - { - emit aboutToHideToolTip(m_tooltip_item); - m_tooltip_item->tooltip()->hide(); - m_tooltip_item = 0; - } - } break; } default: { break; } } return QTreeWidget::event(e); } -void Smb4KNetworkBrowser::mouseMoveEvent(QMouseEvent *e) -{ - // Find the item over which the user moved the mouse: - Smb4KNetworkBrowserItem *item = static_cast(itemAt(e->pos())); - - if (item) - { - emit itemEntered(item, columnAt(e->pos().x())); - - // Hide tool tip if the items diverge. - if (m_tooltip_item && m_tooltip_item->tooltip()->networkItem() != item->networkItem()) - { - emit aboutToHideToolTip(m_tooltip_item); - m_tooltip_item->tooltip()->hide(); - m_tooltip_item = 0; - } - } - else - { - // Hide the tool tip - if (m_tooltip_item) - { - emit aboutToHideToolTip(m_tooltip_item); - m_tooltip_item->tooltip()->hide(); - m_tooltip_item = 0; - } - } - - QTreeWidget::mouseMoveEvent(e); -} - - -void Smb4KNetworkBrowser::leaveEvent(QEvent *e) -{ - if (m_tooltip_item) - { - emit aboutToHideToolTip(m_tooltip_item); - m_tooltip_item->tooltip()->hide(); - m_tooltip_item = 0; - } - - m_mouse_inside = false; - - QTreeWidget::leaveEvent(e); -} - - -void Smb4KNetworkBrowser::enterEvent(QEvent *e) -{ - m_mouse_inside = true; - - QTreeWidget::enterEvent(e); -} - - void Smb4KNetworkBrowser::mousePressEvent(QMouseEvent *e) { - // Hide the current tool tip so that it is not in the way. - if (m_tooltip_item) - { - emit aboutToHideToolTip(m_tooltip_item); - m_tooltip_item->tooltip()->hide(); - m_tooltip_item = 0; - } - // Get the item that is under the mouse. If there is no // item, unselect the current item. QTreeWidgetItem *item = itemAt(e->pos()); if (!item && currentItem()) { currentItem()->setSelected(false); setCurrentItem(0); - emit itemPressed(currentItem(), -1); } QTreeWidget::mousePressEvent(e); } -void Smb4KNetworkBrowser::focusOutEvent(QFocusEvent *e) -{ - QTreeWidget::focusOutEvent(e); -} - - -void Smb4KNetworkBrowser::wheelEvent(QWheelEvent *e) -{ - if (m_tooltip_item) - { - emit aboutToHideToolTip(m_tooltip_item); - m_tooltip_item->tooltip()->hide(); - m_tooltip_item = 0; - } - - QTreeWidget::wheelEvent(e); -} - - ///////////////////////////////////////////////////////////////////////////// // SLOT IMPLEMENTATIONS ///////////////////////////////////////////////////////////////////////////// -void Smb4KNetworkBrowser::slotItemEntered(QTreeWidgetItem *item, int /*column*/) -{ - Smb4KNetworkBrowserItem *browser_item = static_cast(item); - - if (m_tooltip_item && m_tooltip_item != browser_item) - { - emit aboutToHideToolTip(m_tooltip_item); - m_tooltip_item->tooltip()->hide(); - m_tooltip_item = 0; - } -} - - -void Smb4KNetworkBrowser::slotViewportEntered() -{ - if (m_tooltip_item) - { - emit aboutToHideToolTip(m_tooltip_item); - m_tooltip_item->tooltip()->hide(); - m_tooltip_item = 0; - } -} - - void Smb4KNetworkBrowser::slotItemActivated(QTreeWidgetItem *item, int /*column*/) { - if (m_tooltip_item) - { - emit aboutToHideToolTip(m_tooltip_item); - m_tooltip_item->tooltip()->hide(); - m_tooltip_item = 0; - } - // Only do something if there are no keyboard modifiers pressed // and there is only one item selected. if (QApplication::keyboardModifiers() == Qt::NoModifier && selectedItems().size() == 1) { if (item) { switch (item->type()) { case Workgroup: case Host: { if (!item->isExpanded()) { expandItem(item); } else { collapseItem(item); } break; } default: { break; } } } } } void Smb4KNetworkBrowser::slotItemSelectionChanged() { if (selectedItems().size() > 1) { // If multiple items are selected, only allow shares // to stay selected. for (int i = 0; i < selectedItems().size(); ++i) { Smb4KNetworkBrowserItem *item = static_cast(selectedItems()[i]); if (item) { switch (item->networkItem()->type()) { case Workgroup: case Host: { item->setSelected(false); break; } case Share: { if (item->shareItem()->isPrinter()) { item->setSelected(false); } break; } default: { break; } } } } } } diff --git a/smb4k/smb4knetworkbrowser.h b/smb4k/smb4knetworkbrowser.h index 4894b4a..49e099e 100644 --- a/smb4k/smb4knetworkbrowser.h +++ b/smb4k/smb4knetworkbrowser.h @@ -1,186 +1,105 @@ /*************************************************************************** smb4knetworkbrowser - The network browser widget of Smb4K. ------------------- begin : Mo Jan 8 2007 copyright : (C) 2007-2019 by Alexander Reinholdt email : alexander.reinholdt@kdemail.net ***************************************************************************/ /*************************************************************************** * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, but * * WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * * General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., 51 Franklin Street, Suite 500, Boston,* * MA 02110-1335, USA * ***************************************************************************/ #ifndef SMB4KNETWORKBROWSER_H #define SMB4KNETWORKBROWSER_H // Qt includes #include +// KDE includes +#include + // forward declarations class Smb4KNetworkBrowserItem; -class Smb4KToolTip; /** * This is the network neighborhood browser widget. * * @author Alexander Reinholdt */ class Smb4KNetworkBrowser : public QTreeWidget { Q_OBJECT public: /** * The constructor * * @param parent The parent widget */ explicit Smb4KNetworkBrowser(QWidget *parent = 0); /** * The destructor */ ~Smb4KNetworkBrowser(); /** * Enumeration for the columns in the list view. */ enum Columns{ Network = 0, Type = 1, IP = 2, Comment = 3 }; - /** - * This function returns TRUE if the mouse is inside the network - * browser widget and FALSE otherwise. - * - * @returns TRUE if the mouse is inside the widget. - */ - bool mouseInsideWidget() { return m_mouse_inside; } - - signals: - /** - * This signal is emitted when a tool tip is about to be shown. - * - * @param item The network browser item - */ - void aboutToShowToolTip(Smb4KNetworkBrowserItem *item); - - /** - * This signal is emitted when a tool tip is about to be hidden. - * - * @param item The network browser item - */ - void aboutToHideToolTip(Smb4KNetworkBrowserItem *item); - protected: /** * Reimplemented from QWidget. */ bool event(QEvent *e) override; - /** - * Reimplemented from QWidget. This function keeps track of the - * mouse position and handles the tool tips. - * - * @param e The mouse event - */ - void mouseMoveEvent(QMouseEvent *e) override; - - /** - * Reimplemented from QWidget. This function emits the signal - * mouseOutside(). - * - * @param e The event object - */ - void leaveEvent(QEvent *e) override; - - /** - * Reimplemented from QWidget. This function emits the signal - * mouseInside(). - * - * @param e The event object - */ - void enterEvent(QEvent *e) override; - /** * Reimplemented from QAbstractItemView. This function handles * mouse press events. * * @param e The mouse event object */ void mousePressEvent(QMouseEvent *e) override; - /** - * Reimplemented from QAbstractItemView. This function is used - * to stop the auto selection. - * - * @param e The focus event - */ - void focusOutEvent(QFocusEvent *e) override; - - /** - * Reimplemented from QWidget. This function is used to handle - * the tooltip. - * - * @param e The wheel event - */ - void wheelEvent(QWheelEvent *e) override; - protected slots: - /** - * This slot is used to change the cursor over an item if appropriate. - * - * @param item The item that was entered. - * - * @param column The column where the item was entered. - */ - void slotItemEntered(QTreeWidgetItem *item, int column); - - /** - * This slot is invoked when the viewport is entered. It is used - * to hide the tool tip if needed. - */ - void slotViewportEntered(); - /** * This slot is called when the user activated an item. It is used * to open the item if it is expandable. * @param item The item that has been activated. * @param column The column where the item was activated. */ void slotItemActivated(QTreeWidgetItem *item, int column); /** * Take care that only shares are selected when the user marks multiple * shares. */ void slotItemSelectionChanged(); private: /** - * The item for that a tool tip is shown - */ - Smb4KNetworkBrowserItem *m_tooltip_item; - - /** - * Mouse inside the widget? + * The tool top widget */ - bool m_mouse_inside; + KToolTipWidget *m_toolTip; }; #endif diff --git a/smb4k/smb4knetworkbrowseritem.cpp b/smb4k/smb4knetworkbrowseritem.cpp index fa6ebee..635c46c 100644 --- a/smb4k/smb4knetworkbrowseritem.cpp +++ b/smb4k/smb4knetworkbrowseritem.cpp @@ -1,278 +1,570 @@ /*************************************************************************** smb4knetworkbrowseritem - Smb4K's network browser list item. ------------------- begin : Mo Jan 8 2007 - copyright : (C) 2007-2019 by Alexander Reinholdt + copyright : (C) 2007-2020 by Alexander Reinholdt email : alexander.reinholdt@kdemail.net ***************************************************************************/ /*************************************************************************** * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, but * * WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * * General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., 51 Franklin Street, Suite 500, Boston,* * MA 02110-1335, USA * ***************************************************************************/ // application specific includes #include "smb4knetworkbrowseritem.h" #include "core/smb4kglobal.h" #include "core/smb4kworkgroup.h" #include "core/smb4khost.h" #include "core/smb4kshare.h" // Qt includes #include #include #include +#include +#include +#include + +// KDE includes +#include +#include +#include using namespace Smb4KGlobal; Smb4KNetworkBrowserItem::Smb4KNetworkBrowserItem(QTreeWidget *parent, const NetworkItemPtr &item) : QTreeWidgetItem(parent, item->type()), m_item(item) { - m_tooltip = new Smb4KToolTip(); - m_tooltip->setup(Smb4KToolTip::NetworkBrowser, m_item); - switch (m_item->type()) { case Workgroup: { WorkgroupPtr workgroup = m_item.staticCast(); setText(Network, workgroup->workgroupName()); setIcon(Network, workgroup->icon()); break; } case Host: { HostPtr host = m_item.staticCast(); setText(Network, host->hostName()); setText(IP, host->ipAddress()); setText(Comment, host->comment()); if (host->isMasterBrowser()) { for (int i = 0; i < columnCount(); ++i) { QBrush brush(Qt::darkBlue); setForeground(i, brush); } } setIcon(Network, host->icon()); break; } case Share: { SharePtr share = m_item.staticCast(); setText(Network, share->shareName()); setText(Type, share->shareTypeString()); setText(Comment, share->comment()); if (!share->isPrinter() && share->isMounted()) { for (int i = 0; i < columnCount(); ++i) { QFont f = font(i); f.setItalic(true); setFont(i, f); } } setIcon(Network, share->icon()); break; } default: { break; } } + + setupToolTipContentsWidget(); } Smb4KNetworkBrowserItem::Smb4KNetworkBrowserItem(QTreeWidgetItem *parent, const NetworkItemPtr &item) : QTreeWidgetItem(parent, item->type()), m_item(item) { - m_tooltip = new Smb4KToolTip(); - m_tooltip->setup(Smb4KToolTip::NetworkBrowser, m_item); - switch (m_item->type()) { case Workgroup: { WorkgroupPtr workgroup = m_item.staticCast(); setText(Network, workgroup->workgroupName()); setIcon(Network, workgroup->icon()); break; } case Host: { HostPtr host = m_item.staticCast(); setText(Network, host->hostName()); setText(IP, host->ipAddress()); setText(Comment, host->comment()); if (host->isMasterBrowser()) { for (int i = 0; i < columnCount(); ++i) { QBrush brush(Qt::darkBlue); setForeground(i, brush); } } setIcon(Network, host->icon()); break; } case Share: { SharePtr share = m_item.staticCast(); setText(Network, share->shareName()); setText(Type, share->shareTypeString()); setText(Comment, share->comment()); if (!share->isPrinter() && share->isMounted()) { for (int i = 0; i < columnCount(); ++i) { QFont f = font(i); f.setItalic(true); setFont(i, f); } } setIcon(Network, share->icon()); break; } default: { break; } } + + setupToolTipContentsWidget(); } Smb4KNetworkBrowserItem::~Smb4KNetworkBrowserItem() { - delete m_tooltip; + m_toolTipContentsWidget.clear(); } WorkgroupPtr Smb4KNetworkBrowserItem::workgroupItem() { if (!m_item || (m_item && m_item->type() != Workgroup)) { return WorkgroupPtr(); } return m_item.staticCast(); } HostPtr Smb4KNetworkBrowserItem::hostItem() { if (!m_item || (m_item && m_item->type() != Host)) { return HostPtr(); } return m_item.staticCast(); } SharePtr Smb4KNetworkBrowserItem::shareItem() { if (!m_item || (m_item && m_item->type() != Share)) { return SharePtr(); } return m_item.staticCast(); } const NetworkItemPtr &Smb4KNetworkBrowserItem::networkItem() { return m_item; } void Smb4KNetworkBrowserItem::update() { switch (m_item->type()) { case Host: { HostPtr host = m_item.staticCast(); // Adjust the item's color. if (host->isMasterBrowser()) { for (int i = 0; i < columnCount(); ++i) { QBrush brush(Qt::darkBlue); setForeground(i, brush); } } else { for (int i = 0; i < columnCount(); ++i) { QBrush brush = QApplication::palette().text(); setForeground(i, brush); } } // Set the IP address setText(IP, host->ipAddress()); // Set the comment setText(Comment, host->comment()); break; } case Share: { SharePtr share = m_item.staticCast(); // Set the comment setText(Comment, share->comment()); // Set the icon setIcon(Network, share->icon()); // Set the font for (int i = 0; i < columnCount(); ++i) { QFont f = font(i); f.setItalic(share->isMounted()); setFont(i, f); } break; } default: { break; } } - m_tooltip->update(Smb4KToolTip::NetworkBrowser, m_item); + setupToolTipContentsWidget(); } -Smb4KToolTip* Smb4KNetworkBrowserItem::tooltip() +QWidget *Smb4KNetworkBrowserItem::toolTipContentsWidget() { - return m_tooltip; + return m_toolTipContentsWidget; } + + +void Smb4KNetworkBrowserItem::setupToolTipContentsWidget() +{ + // + // The layout + // + QHBoxLayout *mainLayout = nullptr; + + // + // Make sure the widget exists + // + if (!m_toolTipContentsWidget) + { + m_toolTipContentsWidget = new QWidget(treeWidget()); + mainLayout = new QHBoxLayout(m_toolTipContentsWidget); + } + else + { + mainLayout = qobject_cast(m_toolTipContentsWidget->layout()); + } + + // + // Update the contents, if possible + // + if (!m_toolTipContentsWidget->layout()->isEmpty()) + { + switch (m_item->type()) + { + case Workgroup: + { + WorkgroupPtr workgroup = m_item.staticCast(); + QLabel *masterBrowserName = m_toolTipContentsWidget->findChild("MasterBrowserName"); + + if (workgroup->hasMasterBrowserIpAddress()) + { + masterBrowserName->setText(workgroup->masterBrowserName()+" ("+workgroup->masterBrowserIpAddress()+')'); + } + else + { + masterBrowserName->setText(workgroup->masterBrowserName()); + } + break; + } + case Host: + { + HostPtr host = m_item.staticCast(); + m_toolTipContentsWidget->findChild("CommentString")->setText(!host->comment().isEmpty() ? host->comment() : "-"); + m_toolTipContentsWidget->findChild("IPAddressString")->setText(host->hasIpAddress() ? host->ipAddress() : "-"); + break; + } + case Share: + { + SharePtr share = m_item.staticCast(); + + m_toolTipContentsWidget->findChild("CommentString")->setText(!share->comment().isEmpty() ? share->comment() : "-"); + m_toolTipContentsWidget->findChild("IPAddressString")->setText(share->hasHostIpAddress() ? share->hostIpAddress() : "-"); + + QLabel *mountedState = m_toolTipContentsWidget->findChild("MountedState"); + + if (!share->isPrinter()) + { + mountedState->setText(share->isMounted() ? i18n("yes") : i18n("no")); + } + else + { + mountedState->setText("-"); + } + break; + } + default: + { + break; + } + } + + return; + } + + // + // Set up the widget + // + + // Icon + QLabel *iconLabel = new QLabel(m_toolTipContentsWidget); + iconLabel->setPixmap(m_item->icon().pixmap(KIconLoader::SizeEnormous)); + mainLayout->addWidget(iconLabel, Qt::AlignHCenter); + + // Header + QGridLayout *descriptionLayout = new QGridLayout(); + mainLayout->addLayout(descriptionLayout); + + QLabel *caption = new QLabel(m_toolTipContentsWidget); + caption->setForegroundRole(QPalette::ToolTipText); + caption->setBackgroundRole(QPalette::AlternateBase); + + QFont captionFont = caption->font(); + captionFont.setBold(true); + caption->setFont(captionFont); + + descriptionLayout->addWidget(caption, 0, 0, 1, 2, Qt::AlignHCenter); + + KSeparator *separator = new KSeparator(Qt::Horizontal, m_toolTipContentsWidget); + separator->setForegroundRole(QPalette::ToolTipText); + + descriptionLayout->addWidget(separator, 1, 0, 1, 2, 0); + + // Type + QLabel *typeCaption = new QLabel(i18n("Type:"), m_toolTipContentsWidget); + typeCaption->setForegroundRole(QPalette::ToolTipText); + + descriptionLayout->addWidget(typeCaption, 2, 0, Qt::AlignRight); + + QLabel *typeName = new QLabel(m_toolTipContentsWidget); + typeName->setForegroundRole(QPalette::ToolTipText); + + descriptionLayout->addWidget(typeName, 2, 1, 0); + + switch (m_item->type()) + { + case Workgroup: + { + WorkgroupPtr workgroup = m_item.staticCast(); + + caption->setText(workgroup->workgroupName()); + typeName->setText(i18n("Workgroup")); + + // Master browser + QLabel *masterBrowserLabel = new QLabel(i18n("Master Browser:"), m_toolTipContentsWidget); + masterBrowserLabel->setForegroundRole(QPalette::ToolTipText); + + descriptionLayout->addWidget(masterBrowserLabel, 3, 0, Qt::AlignRight); + + QLabel *masterBrowserName = new QLabel(m_toolTipContentsWidget); + masterBrowserName->setObjectName("MasterBrowserName"); + masterBrowserName->setForegroundRole(QPalette::ToolTipText); + + if (workgroup->hasMasterBrowserIpAddress()) + { + masterBrowserName->setText(QString("%1 (%2)").arg(workgroup->masterBrowserName()).arg(workgroup->masterBrowserIpAddress())); + } + else + { + masterBrowserName->setText(workgroup->masterBrowserName()); + } + + descriptionLayout->addWidget(masterBrowserName, 3, 1, 0); + + descriptionLayout->addItem(new QSpacerItem(1, 1, QSizePolicy::Expanding, QSizePolicy::Minimum), 4, 0, 2, 1, 0); + + break; + } + case Host: + { + HostPtr host = m_item.staticCast(); + caption->setText(host->hostName()); + typeName->setText(i18n("Host")); + + // Comment + QLabel *commentLabel = new QLabel(i18n("Comment:"), m_toolTipContentsWidget); + commentLabel->setForegroundRole(QPalette::ToolTipText); + + descriptionLayout->addWidget(commentLabel, 3, 0, Qt::AlignRight); + + QLabel *commentString = new QLabel(!host->comment().isEmpty() ? host->comment() : "-", m_toolTipContentsWidget); + commentString->setObjectName("CommentString"); + commentString->setForegroundRole(QPalette::ToolTipText); + + descriptionLayout->addWidget(commentString, 3, 1, 0); + + // IP address + QLabel *ipAddressLabel = new QLabel(i18n("IP Address:"), m_toolTipContentsWidget); + ipAddressLabel->setForegroundRole(QPalette::ToolTipText); + + descriptionLayout->addWidget(ipAddressLabel, 4, 0, Qt::AlignRight); + + QLabel *ipAddress = new QLabel(host->hasIpAddress() ? host->ipAddress() : "-", m_toolTipContentsWidget); + ipAddress->setObjectName("IPAddressString"); + ipAddress->setForegroundRole(QPalette::ToolTipText); + + descriptionLayout->addWidget(ipAddress, 4, 1, 0); + + // Workgroup + QLabel *workgroupLabel = new QLabel(i18n("Workgroup:"), m_toolTipContentsWidget); + workgroupLabel->setForegroundRole(QPalette::ToolTipText); + + descriptionLayout->addWidget(workgroupLabel, 5, 0, Qt::AlignRight); + + QLabel *workgroupName = new QLabel(host->workgroupName(), m_toolTipContentsWidget); + workgroupName->setForegroundRole(QPalette::ToolTipText); + + descriptionLayout->addWidget(workgroupName, 5, 1, 0); + + descriptionLayout->addItem(new QSpacerItem(1, 1, QSizePolicy::Expanding, QSizePolicy::Minimum), 6, 0, 2, 1, 0); + + break; + } + case Share: + { + SharePtr share = m_item.staticCast(); + caption->setText(share->shareName()); + typeName->setText(i18n("Share (%1)", share->shareTypeString())); + + // Comment + QLabel *commentLabel = new QLabel(i18n("Comment:"), m_toolTipContentsWidget); + commentLabel->setForegroundRole(QPalette::ToolTipText); + + descriptionLayout->addWidget(commentLabel, 3, 0, Qt::AlignRight); + + QLabel *commentString = new QLabel(!share->comment().isEmpty() ? share->comment() : "-", m_toolTipContentsWidget); + commentString->setObjectName("CommentString"); + commentString->setForegroundRole(QPalette::ToolTipText); + + descriptionLayout->addWidget(commentString, 3, 1, 0); + + // State (mounted/not mounted) + QLabel *mountedLabel = new QLabel(i18n("Mounted:"), m_toolTipContentsWidget); + mountedLabel->setForegroundRole(QPalette::ToolTipText); + + descriptionLayout->addWidget(mountedLabel, 4, 0, Qt::AlignRight); + + QLabel *mountedState = nullptr; + + if (!share->isPrinter()) + { + mountedState = new QLabel(share->isMounted() ? i18n("yes") : i18n("no"), m_toolTipContentsWidget); + } + else + { + mountedState = new QLabel("-", m_toolTipContentsWidget); + } + + mountedState->setObjectName("MountedState"); + mountedState->setForegroundRole(QPalette::ToolTipText); + + descriptionLayout->addWidget(mountedState, 4, 1, 0); + + // Host + QLabel *hostLabel = new QLabel(i18n("Host:"), m_toolTipContentsWidget); + hostLabel->setForegroundRole(QPalette::ToolTipText); + + descriptionLayout->addWidget(hostLabel, 5, 0, Qt::AlignRight); + + QLabel *hostName = new QLabel(share->hostName(), m_toolTipContentsWidget); + hostName->setForegroundRole(QPalette::ToolTipText); + + descriptionLayout->addWidget(hostName, 5, 1, 0); + + // IP address + QLabel *ipAddressLabel = new QLabel(i18n("IP Address:"), m_toolTipContentsWidget); + ipAddressLabel->setForegroundRole(QPalette::ToolTipText); + + descriptionLayout->addWidget(ipAddressLabel, 6, 0, Qt::AlignRight); + + QLabel *ipAddressString = new QLabel(share->hasHostIpAddress() ? share->hostIpAddress() : "-", m_toolTipContentsWidget); + ipAddressString->setObjectName("IPAddressString"); + ipAddressString->setForegroundRole(QPalette::ToolTipText); + + descriptionLayout->addWidget(ipAddressString, 6, 1, 0); + + // Location + QLabel *locationLabel = new QLabel(i18n("Location:"), m_toolTipContentsWidget); + locationLabel->setForegroundRole(QPalette::ToolTipText); + + descriptionLayout->addWidget(locationLabel, 7, 0, Qt::AlignRight); + + QLabel *locationString = new QLabel(share->displayString(), m_toolTipContentsWidget); + locationString->setForegroundRole(QPalette::ToolTipText); + + descriptionLayout->addWidget(locationString, 7, 1, 0); + + descriptionLayout->addItem(new QSpacerItem(1, 1, QSizePolicy::Expanding, QSizePolicy::Minimum), 8, 0, 2, 1, 0); + + break; + } + default: + { + break; + } + } + + m_toolTipContentsWidget->adjustSize(); +} + + + diff --git a/smb4k/smb4knetworkbrowseritem.h b/smb4k/smb4knetworkbrowseritem.h index bf165e0..500cb46 100644 --- a/smb4k/smb4knetworkbrowseritem.h +++ b/smb4k/smb4knetworkbrowseritem.h @@ -1,127 +1,133 @@ /*************************************************************************** smb4knetworkbrowseritem - Smb4K's network browser list item. ------------------- begin : Mo Jan 8 2007 - copyright : (C) 2007-2019 by Alexander Reinholdt + copyright : (C) 2007-2020 by Alexander Reinholdt email : alexander.reinholdt@kdemail.net ***************************************************************************/ /*************************************************************************** * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, but * * WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * * General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., 51 Franklin Street, Suite 500, Boston,* * MA 02110-1335, USA * ***************************************************************************/ #ifndef SMB4KNETWORKBROWSERITEM_H #define SMB4KNETWORKBROWSERITEM_H // application specific includes #include "core/smb4kglobal.h" -#include "smb4ktooltip.h" // Qt includes #include #include +#include class Smb4KNetworkBrowser; class Smb4KNetworkBrowserItem : public QTreeWidgetItem { public: /** * The constructor for toplevel items. * * @param parent The parent tree widget * @param item The network item */ Smb4KNetworkBrowserItem(QTreeWidget *parent, const NetworkItemPtr &item); /** * The constructor for child items. * * @param parent The parent tree widget item. * @param item The network item */ Smb4KNetworkBrowserItem(QTreeWidgetItem *parent, const NetworkItemPtr &item); /** * The destructor. */ virtual ~Smb4KNetworkBrowserItem(); /** * Columns of the item. */ enum Columns{ Network = 0, Type = 1, IP = 2, Comment = 3 }; /** * This function is provided for convenience. It returns a pointer to * the Smb4KWorkgroup object if it is present or NULL if it is not. * * @returns a pointer to the workgroup item or NULL. */ WorkgroupPtr workgroupItem(); /** * This function is provided for convenience. It returns a pointer to * the Smb4KHost object if it is present or NULL if it is not. * * @returns a pointer to the host item or NULL. */ HostPtr hostItem(); /** * This function is provided for convenience. It returns a pointer to * the Smb4KShare object if it is present or NULL if it is not. * * @returns a pointer to the share item or NULL. */ SharePtr shareItem(); /** * This function returns the encapsulated network item. * * @returns a pointer to the encapsulated Smb4KBasicNetworkItem object * or NULL if there is no item defined (this should never happen). */ const NetworkItemPtr &networkItem(); /** * This function updates the internal network item. */ void update(); /** - * This function returns the tool tip of this item. + * This function returns the widget with contents that is to be shown + * in the tooltip. * - * @returns the tool tip. + * @returns the widget that is to be shown in the tooltip */ - Smb4KToolTip *tooltip(); - + QWidget *toolTipContentsWidget(); + private: + /** + * This function sets up the tooltip contents widget + */ + void setupToolTipContentsWidget(); + /** * The network item */ NetworkItemPtr m_item; /** - * The tool tip of this item + * The widget with the information for the tooltip */ - Smb4KToolTip *m_tooltip; + QPointer m_toolTipContentsWidget; }; #endif diff --git a/smb4k/smb4ksharesview.cpp b/smb4k/smb4ksharesview.cpp index 0c93c15..476769d 100644 --- a/smb4k/smb4ksharesview.cpp +++ b/smb4k/smb4ksharesview.cpp @@ -1,395 +1,301 @@ /*************************************************************************** This is the shares view of Smb4K. ------------------- begin : Mo Dez 4 2006 - copyright : (C) 2006-2019 by Alexander Reinholdt + copyright : (C) 2006-2020 by Alexander Reinholdt email : alexander.reinholdt@kdemail.net ***************************************************************************/ /*************************************************************************** * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, but * * WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * * General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., 51 Franklin Street, Suite 500, Boston,* * MA 02110-1335, USA * ***************************************************************************/ // application specific includes #include "smb4ksharesview.h" #include "smb4ksharesviewitem.h" -#include "smb4ktooltip.h" #include "core/smb4kshare.h" #include "core/smb4ksettings.h" // Qt includes #include #include #include #include #include +#include +#include // KDE includes #include Smb4KSharesView::Smb4KSharesView(QWidget *parent) : QListWidget(parent) { setMouseTracking(true); setSelectionMode(ExtendedSelection); setResizeMode(Adjust); setSortingEnabled(true); setWordWrap(true); setAcceptDrops(true); setDragEnabled(true); setDropIndicatorShown(true); setUniformItemSizes(true); setWrapping(true); + m_toolTip = new KToolTipWidget(this); + setContextMenuPolicy(Qt::CustomContextMenu); - - m_tooltipItem = 0; - m_mouseInside = false; - - // - // Connections - // - connect(this, SIGNAL(itemEntered(QListWidgetItem*)), this, SLOT(slotItemEntered(QListWidgetItem*))); - connect(this, SIGNAL(viewportEntered()), this, SLOT(slotViewportEntered())); } Smb4KSharesView::~Smb4KSharesView() { } void Smb4KSharesView::setViewMode(QListView::ViewMode mode, int iconSize) { // // Set the view mode // QListWidget::setViewMode(mode); // // Make adjustments // switch(mode) { case IconMode: { setUniformItemSizes(true); setIconSize(QSize(iconSize, iconSize)); setSpacing(5); break; } case ListMode: { setUniformItemSizes(false); setIconSize(QSize(iconSize, iconSize)); setSpacing(0); break; } default: { break; } } // // Align the items // for (int i = 0; i < count(); ++i) { Smb4KSharesViewItem *viewItem = static_cast(item(i)); viewItem->setItemAlignment(mode); } } bool Smb4KSharesView::event(QEvent *e) { switch (e->type()) { case QEvent::ToolTip: { // Intercept the tool tip event and show our own tool tip. QPoint pos = viewport()->mapFromGlobal(cursor().pos()); Smb4KSharesViewItem *item = static_cast(itemAt(pos)); if (item) { if (Smb4KSettings::showShareToolTip()) { - m_tooltipItem = item; - emit aboutToShowToolTip(m_tooltipItem); - m_tooltipItem->tooltip()->show(cursor().pos()); - } - else - { - if (m_tooltipItem) + QPoint tooltipPos = cursor().pos(); + + int testWidth = item->toolTipContentsWidget()->width() + cursor().pos().x() + m_toolTip->layout()->contentsMargins().left() + m_toolTip->layout()->contentsMargins().right(); + + if (QApplication::screenAt(pos)->virtualSize().width() < testWidth) { - emit aboutToHideToolTip(m_tooltipItem); - m_tooltipItem->tooltip()->hide(); - m_tooltipItem = 0; + tooltipPos.setX(cursor().pos().x() - item->toolTipContentsWidget()->width() - m_toolTip->layout()->contentsMargins().left() - m_toolTip->layout()->contentsMargins().right()); } - } - } - else - { - if (m_tooltipItem) - { - emit aboutToHideToolTip(m_tooltipItem); - m_tooltipItem->tooltip()->hide(); - m_tooltipItem = 0; + + int testHeight = item->toolTipContentsWidget()->height() + cursor().pos().y() + m_toolTip->layout()->contentsMargins().top() + m_toolTip->layout()->contentsMargins().bottom(); + + if (QApplication::screenAt(pos)->virtualSize().height() < testHeight) + { + tooltipPos.setY(cursor().pos().y() - item->toolTipContentsWidget()->height() - m_toolTip->layout()->contentsMargins().top() - m_toolTip->layout()->contentsMargins().bottom()); + } + + m_toolTip->showAt(tooltipPos, item->toolTipContentsWidget(), nativeParentWidget()->windowHandle()); } } break; } default: { break; } } return QListWidget::event(e); } -void Smb4KSharesView::leaveEvent(QEvent *e) -{ - if (m_tooltipItem) - { - emit aboutToHideToolTip(m_tooltipItem); - m_tooltipItem->tooltip()->hide(); - m_tooltipItem = 0; - } - - m_mouseInside = false; - QListWidget::leaveEvent(e); -} - - -void Smb4KSharesView::enterEvent(QEvent *e) -{ - m_mouseInside = true; - QListWidget::enterEvent(e); -} - - void Smb4KSharesView::mousePressEvent(QMouseEvent *e) { - // Hide the current tool tip so that it is not in the way. - if (m_tooltipItem) - { - emit aboutToHideToolTip(m_tooltipItem); - m_tooltipItem->tooltip()->hide(); - m_tooltipItem = 0; - } - // Get the item that is under the mouse. If there is no // item, unselect the current item. QListWidgetItem *item = itemAt(e->pos()); if (!item && !selectedItems().isEmpty()) { clearSelection(); setCurrentItem(0); emit itemPressed(currentItem()); } QListWidget::mousePressEvent(e); } -void Smb4KSharesView::focusOutEvent(QFocusEvent *e) -{ - QListWidget::focusOutEvent(e); -} - - -void Smb4KSharesView::wheelEvent(QWheelEvent *e) -{ - if (m_tooltipItem) - { - emit aboutToHideToolTip(m_tooltipItem); - m_tooltipItem->tooltip()->hide(); - m_tooltipItem = 0; - } - - QListWidget::wheelEvent(e); -} - - void Smb4KSharesView::dragEnterEvent(QDragEnterEvent *e) { if (e->mimeData()->hasUrls()) { e->accept(); } else { e->ignore(); } } void Smb4KSharesView::dragMoveEvent(QDragMoveEvent *e) { // Let the QAbstractItemView do the highlighting of the item, etc. QAbstractItemView::dragMoveEvent(e); // Now we do our thing. Smb4KSharesViewItem *item = static_cast(itemAt(e->pos())); if (item && !item->shareItem()->isInaccessible() && (item->flags() & Qt::ItemIsDropEnabled) && (e->proposedAction() & (Qt::CopyAction | Qt::MoveAction))) { QUrl url = QUrl::fromLocalFile(item->shareItem()->path()); if (e->source() == this && e->mimeData()->urls().first() == url) { e->ignore(); } else { e->accept(); } } else { e->ignore(); } } void Smb4KSharesView::dropEvent(QDropEvent *e) { // Get the item and process the drop event Smb4KSharesViewItem *item = static_cast(itemAt(e->pos())); if (item && !item->shareItem()->isInaccessible() && (e->proposedAction() & (Qt::CopyAction|Qt::MoveAction))) { QUrl url = QUrl::fromLocalFile(item->shareItem()->path()); if (e->source() == this && e->mimeData()->urls().first() == url) { e->ignore(); } else { e->acceptProposedAction(); emit acceptedDropEvent(item, e); e->accept(); } } else { e->ignore(); } } Qt::DropActions Smb4KSharesView::supportedDropActions() const { // Only allow copying and linking. return (Qt::CopyAction|Qt::LinkAction); } QMimeData *Smb4KSharesView::mimeData(const QList list) const { QMimeData *mimeData = new QMimeData(); QList urls; for (int i = 0; i < list.count(); ++i) { Smb4KSharesViewItem *item = static_cast(list.at(i)); urls << QUrl::fromLocalFile(item->shareItem()->path()); } mimeData->setUrls(urls); return mimeData; } void Smb4KSharesView::startDrag(Qt::DropActions supported) { - if (m_tooltipItem) - { - emit aboutToHideToolTip(m_tooltipItem); - m_tooltipItem->tooltip()->hide(); - m_tooltipItem = 0; - } - QList list = selectedItems(); if (!list.isEmpty()) { QMimeData *data = mimeData(list); if (!data) { return; } QDrag *drag = new QDrag(this); QPixmap pixmap; if (list.count() == 1) { Smb4KSharesViewItem *item = static_cast(list.first()); pixmap = item->icon().pixmap(KIconLoader::SizeMedium); } else { pixmap = KDE::icon("document-multiple").pixmap(KIconLoader::SizeMedium); } drag->setPixmap(pixmap); drag->setMimeData(data); drag->exec(supported, Qt::IgnoreAction); } } - -///////////////////////////////////////////////////////////////////////////// -// SLOT IMPLEMENTATIONS -///////////////////////////////////////////////////////////////////////////// - -void Smb4KSharesView::slotItemEntered(QListWidgetItem *item) -{ - Smb4KSharesViewItem *share_item = static_cast(item); - - if (m_tooltipItem && m_tooltipItem != share_item) - { - emit aboutToHideToolTip(m_tooltipItem); - m_tooltipItem->tooltip()->hide(); - m_tooltipItem = 0; - } -} - - -void Smb4KSharesView::slotViewportEntered() -{ - // Hide the tool tip. - if (m_tooltipItem) - { - emit aboutToHideToolTip(m_tooltipItem); - m_tooltipItem->tooltip()->hide(); - m_tooltipItem = 0; - } -} - diff --git a/smb4k/smb4ksharesview.h b/smb4k/smb4ksharesview.h index 72c4c94..3350e3a 100644 --- a/smb4k/smb4ksharesview.h +++ b/smb4k/smb4ksharesview.h @@ -1,204 +1,141 @@ /*************************************************************************** This is the shares view of Smb4K. ------------------- begin : Mo Dez 4 2006 - copyright : (C) 2006-2019 by Alexander Reinholdt + copyright : (C) 2006-2020 by Alexander Reinholdt email : alexander.reinholdt@kdemail.net ***************************************************************************/ /*************************************************************************** * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, but * * WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * * General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., 51 Franklin Street, Suite 500, Boston,* * MA 02110-1335, USA * ***************************************************************************/ #ifndef SMB4KSHARESVIEW_H #define SMB4KSHARESVIEW_H // Qt includes #include #include #include +// KDE includes +#include + // forward declarations class Smb4KSharesViewItem; class Smb4KToolTip; /** * This widget class provides the shares view of Smb4K. * * @author Alexander Reinholdt */ class Smb4KSharesView : public QListWidget { Q_OBJECT public: /** * The constructor. * * @param parent The parent widget */ explicit Smb4KSharesView(QWidget *parent = 0); /** * The destructor. */ ~Smb4KSharesView(); /** * Set the view mode. * * @param mode The view mode * @param iconSize The size of the icons */ void setViewMode(ViewMode mode, int iconSize); signals: /** * This signal is emitted when something has been dropped onto * @p item and the drop event was accepted. * * @param item The item on which something has been dropped. * * @param e The drop event. */ void acceptedDropEvent(Smb4KSharesViewItem *item, QDropEvent *e); - - /** - * This signal is emitted when a tool tip is about to be shown. - * - * @param item The shares list view item - */ - void aboutToShowToolTip(Smb4KSharesViewItem *item); - - /** - * This signal is emitted when a tool tip is about to be hidden. - * - * @param item The shares list view item - */ - void aboutToHideToolTip(Smb4KSharesViewItem *item); protected: /** * Reimplemented from QListWidget. */ bool event(QEvent *e) override; - /** - * Reimplemented from QWidget. This function emits the signal - * mouseOutside(). - * - * @param e The event object - */ - void leaveEvent(QEvent *e) override; - - /** - * Reimplemented from QWidget. This function emits the signal - * mouseInside(). - * - * @param e The event object - */ - void enterEvent(QEvent *e) override; - /** * Reimplemented from QAbstractItemView. This function handles * mouse press events. * * @param e The mouse event object */ void mousePressEvent(QMouseEvent *e) override; - /** - * Reimplemented from QAbstractItemView. This function is used - * to stop the auto selection. - * - * @param e The focus event - */ - void focusOutEvent(QFocusEvent *e) override; - - /** - * Reimplemented from QWidget. This function is used to handle - * the tooltip. - * - * @param e The wheel event - */ - void wheelEvent(QWheelEvent *e) override; - /** * Reimplemented to allow dragging and dropping. * * @param e The drag event */ virtual void dragEnterEvent(QDragEnterEvent *e) override; /** * Reimplemented to allow dragging and dropping. * * @param e The drag move event */ void dragMoveEvent(QDragMoveEvent *e) override; /** * Reimplemented to allow dragging and dropping. * * @param e The drop event */ void dropEvent(QDropEvent *e) override; /** * Reimplemented to allow only the copy drop action. */ Qt::DropActions supportedDropActions() const override; /** * Reimplemented to allow dragging. */ QMimeData *mimeData(const QList list) const override; /** * Reimplemented to allow dragging. */ void startDrag(Qt::DropActions supported) override; - protected slots: - /** - * This slot is invoked when an item in the shares view has been entered. - * It is used to display the tool tips. - * - * @param item The item that is under the mouse. - */ - void slotItemEntered(QListWidgetItem *item); - - /** - * This slot is invoked when the viewport is entered. It is used - * to hide the tool tip if needed. - */ - void slotViewportEntered(); - private: /** - * The item for that a tool tip is shown - */ - Smb4KSharesViewItem *m_tooltipItem; - - /** - * Is the mouse inside the widget? + * The tool top widget */ - bool m_mouseInside; + KToolTipWidget *m_toolTip; }; #endif diff --git a/smb4k/smb4ksharesviewitem.cpp b/smb4k/smb4ksharesviewitem.cpp index 7e52006..3021970 100644 --- a/smb4k/smb4ksharesviewitem.cpp +++ b/smb4k/smb4ksharesviewitem.cpp @@ -1,88 +1,258 @@ /*************************************************************************** The item for Smb4K's shares view. ------------------- begin : Di Dez 5 2006 - copyright : (C) 2006-2019 by Alexander Reinholdt + copyright : (C) 2006-2020 by Alexander Reinholdt email : alexander.reinholdt@kdemail.net ***************************************************************************/ /*************************************************************************** * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, but * * WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * * General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., 51 Franklin Street, Suite 500, Boston,* * MA 02110-1335, USA * ***************************************************************************/ // application specific includes #include "smb4ksharesviewitem.h" #include "smb4ksharesview.h" #include "core/smb4kshare.h" +// Qt includes +#include +#include + +// KDE includes +#include +#include +#include + Smb4KSharesViewItem::Smb4KSharesViewItem(Smb4KSharesView *parent, const SharePtr &share) : QListWidgetItem(parent), m_share(share) { setFlags(flags() | Qt::ItemIsDropEnabled); setItemAlignment(parent->viewMode()); - - m_tooltip = new Smb4KToolTip(); - m_tooltip->setup(Smb4KToolTip::SharesView, m_share); - + setText(m_share->displayString()); setIcon(m_share->icon()); + + setupToolTipContentsWidget(); } Smb4KSharesViewItem::~Smb4KSharesViewItem() { - delete m_tooltip; + m_toolTipContentsWidget.clear(); } void Smb4KSharesViewItem::update() { - m_tooltip->update(Smb4KToolTip::SharesView, m_share); - setText(m_share->displayString()); setIcon(m_share->icon()); -} - -Smb4KToolTip* Smb4KSharesViewItem::tooltip() -{ - return m_tooltip; + setupToolTipContentsWidget(); } void Smb4KSharesViewItem::setItemAlignment(QListView::ViewMode mode) { switch (mode) { case QListView::IconMode: { setTextAlignment(Qt::AlignHCenter|Qt::AlignTop); break; } case QListView::ListMode: { setTextAlignment(Qt::AlignAbsolute|Qt::AlignVCenter); break; } default: { break; } } } +QWidget *Smb4KSharesViewItem::toolTipContentsWidget() +{ + return m_toolTipContentsWidget; +} + + +void Smb4KSharesViewItem::setupToolTipContentsWidget() +{ + // + // The layout + // + QHBoxLayout *mainLayout = nullptr; + + // + // Make sure the widget exists + // + if (!m_toolTipContentsWidget) + { + m_toolTipContentsWidget = new QWidget(listWidget()); + mainLayout = new QHBoxLayout(m_toolTipContentsWidget); + } + else + { + mainLayout = qobject_cast(m_toolTipContentsWidget->layout()); + } + + // + // Update the contents, if possible + // + if (!m_toolTipContentsWidget->layout()->isEmpty()) + { + m_toolTipContentsWidget->findChild("IconLabel")->setPixmap(m_share->icon().pixmap(KIconLoader::SizeEnormous)); + m_toolTipContentsWidget->findChild("LoginString")->setText(!m_share->login().isEmpty() ? m_share->login() : i18n("unknown")); + + QString sizeIndication; + + if (m_share->totalDiskSpace() != 0 && m_share->freeDiskSpace() != 0) + { + sizeIndication = i18n("%1 free of %2 (%3 used)", m_share->freeDiskSpaceString(), m_share->totalDiskSpaceString(), m_share->diskUsageString()); + } + else + { + sizeIndication = i18n("unknown"); + } + + m_toolTipContentsWidget->findChild("SizeString")->setText(sizeIndication); + + return; + } + + // + // Set up the widget + // + + // Icon + QLabel *iconLabel = new QLabel(m_toolTipContentsWidget); + iconLabel->setPixmap(m_share->icon().pixmap(KIconLoader::SizeEnormous)); + iconLabel->setObjectName("IconLabel"); + mainLayout->addWidget(iconLabel, Qt::AlignHCenter); + + // Header + QGridLayout *descriptionLayout = new QGridLayout(); + mainLayout->addLayout(descriptionLayout); + + QLabel *caption = new QLabel(m_share->shareName(), m_toolTipContentsWidget); + caption->setForegroundRole(QPalette::ToolTipText); + caption->setBackgroundRole(QPalette::AlternateBase); + + QFont captionFont = caption->font(); + captionFont.setBold(true); + caption->setFont(captionFont); + + descriptionLayout->addWidget(caption, 0, 0, 1, 2, Qt::AlignHCenter); + + KSeparator *separator = new KSeparator(Qt::Horizontal, m_toolTipContentsWidget); + separator->setForegroundRole(QPalette::ToolTipText); + + descriptionLayout->addWidget(separator, 1, 0, 1, 2, 0); + + // Location + QLabel *locationLabel = new QLabel(i18n("Location:"), m_toolTipContentsWidget); + locationLabel->setForegroundRole(QPalette::ToolTipText); + + descriptionLayout->addWidget(locationLabel, 2, 0, Qt::AlignRight); + + QLabel *locationString = new QLabel(m_share->displayString(), m_toolTipContentsWidget); + locationString->setForegroundRole(QPalette::ToolTipText); + + descriptionLayout->addWidget(locationString, 2, 1, 0); + + // Mount point + QLabel *mountpointLabel = new QLabel(i18n("Mountpoint:"), m_toolTipContentsWidget); + mountpointLabel->setForegroundRole(QPalette::ToolTipText); + + descriptionLayout->addWidget(mountpointLabel, 3, 0, Qt::AlignRight); + + QLabel *mountpointString = new QLabel(m_share->path(), m_toolTipContentsWidget); + mountpointString->setForegroundRole(QPalette::ToolTipText); + + descriptionLayout->addWidget(mountpointString, 3, 1, 0); + + // Login + QLabel *loginLabel = new QLabel(i18n("Login:"), m_toolTipContentsWidget); + loginLabel->setForegroundRole(QPalette::ToolTipText); + + descriptionLayout->addWidget(loginLabel, 4, 0, Qt::AlignRight); + + QLabel *loginString = new QLabel(!m_share->login().isEmpty() ? m_share->login() : i18n("unknown"), m_toolTipContentsWidget); + loginString->setObjectName("LoginString"); + loginString->setForegroundRole(QPalette::ToolTipText); + + descriptionLayout->addWidget(loginString, 4, 1, 0); + + // Owner + QLabel *ownerLabel = new QLabel(i18n("Owner:"), m_toolTipContentsWidget); + ownerLabel->setForegroundRole(QPalette::ToolTipText); + + descriptionLayout->addWidget(ownerLabel, 5, 0, Qt::AlignRight); + + QString owner(!m_share->user().loginName().isEmpty() ? m_share->user().loginName() : i18n("unknown")); + QString group(!m_share->group().name().isEmpty() ? m_share->group().name() : i18n("unknown")); + + QLabel *ownerString = new QLabel(QString("%1 - %2").arg(owner, group),m_toolTipContentsWidget); + ownerString->setForegroundRole(QPalette::ToolTipText); + + descriptionLayout->addWidget(ownerString, 5, 1, 0); + + // File system + QLabel *fileSystemLabel = new QLabel(i18n("File system:"), m_toolTipContentsWidget); + fileSystemLabel->setForegroundRole(QPalette::ToolTipText); + + descriptionLayout->addWidget(fileSystemLabel, 6, 0, Qt::AlignRight); + + QLabel *fileSystemString = new QLabel(m_share->fileSystemString(), m_toolTipContentsWidget); + fileSystemString->setForegroundRole(QPalette::ToolTipText); + + descriptionLayout->addWidget(fileSystemString, 6, 1, 0); + + // Size + QLabel *sizeLabel = new QLabel(i18n("Size:"), m_toolTipContentsWidget); + sizeLabel->setForegroundRole(QPalette::ToolTipText); + + descriptionLayout->addWidget(sizeLabel, 7, 0, Qt::AlignRight); + + QString sizeIndication; + + if (m_share->totalDiskSpace() != 0 && m_share->freeDiskSpace() != 0) + { + sizeIndication = i18n("%1 free of %2 (%3 used)", m_share->freeDiskSpaceString(), m_share->totalDiskSpaceString(), m_share->diskUsageString()); + } + else + { + sizeIndication = i18n("unknown"); + } + + QLabel *sizeString = new QLabel(sizeIndication, m_toolTipContentsWidget); + sizeString->setObjectName("SizeString"); + sizeString->setForegroundRole(QPalette::ToolTipText); + + descriptionLayout->addWidget(sizeString, 7, 1, 0); + + descriptionLayout->addItem(new QSpacerItem(1, 1, QSizePolicy::Expanding, QSizePolicy::Minimum), 8, 0, 2, 1, 0); + + m_toolTipContentsWidget->adjustSize(); +} + + + diff --git a/smb4k/smb4ksharesviewitem.h b/smb4k/smb4ksharesviewitem.h index 41fa67c..200de4d 100644 --- a/smb4k/smb4ksharesviewitem.h +++ b/smb4k/smb4ksharesviewitem.h @@ -1,101 +1,108 @@ /*************************************************************************** The item for Smb4K's shares view. ------------------- begin : Di Dez 5 2006 - copyright : (C) 2006-2019 by Alexander Reinholdt + copyright : (C) 2006-2020 by Alexander Reinholdt email : alexander.reinholdt@kdemail.net ***************************************************************************/ /*************************************************************************** * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, but * * WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * * General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., 51 Franklin Street, Suite 500, Boston,* * MA 02110-1335, USA * ***************************************************************************/ #ifndef SMB4KSHARESVIEWITEM_H #define SMB4KSHARESVIEWITEM_H // application specific includes #include "core/smb4kglobal.h" -#include "smb4ktooltip.h" // Qt includes #include +#include +#include // forward declarations class Smb4KSharesView; /** * This class provides the items for the shares icon view * of Smb4K. * * @author Alexander Reinholdt */ class Smb4KSharesViewItem : public QListWidgetItem { public: /** * The constructor. * * @param share The Smb4KShare object that represents the share. * * @param parent The parent widget of this item. */ Smb4KSharesViewItem(Smb4KSharesView *parent, const SharePtr &share); /** * The destructor */ ~Smb4KSharesViewItem(); /** * This function returns the encapsulated Smb4KShare item. * * @returns the encapsulated Smb4KShare item. */ const SharePtr &shareItem() { return m_share; } /** * This function updates the encapsulated Smb4KShare object. */ void update(); - /** - * This function returns the tool tip of this item. - * - * @returns the tool tip. - */ - Smb4KToolTip *tooltip(); - /** * This function modifies the alignment according to the @p mode used in * the parent list widget. */ void setItemAlignment(QListView::ViewMode mode); + /** + * This function returns the widget with contents that is to be shown + * in the tooltip. + * + * @returns the widget that is to be shown in the tooltip + */ + QWidget *toolTipContentsWidget(); + private: + /** + * This function sets up the tooltip contents widget + */ + void setupToolTipContentsWidget(); + /** * The Smb4KShare item */ SharePtr m_share; /** - * The tool tip + * The widget with the information for the tooltip */ - Smb4KToolTip *m_tooltip; + QPointer m_toolTipContentsWidget; }; #endif diff --git a/smb4k/smb4ktooltip.cpp b/smb4k/smb4ktooltip.cpp deleted file mode 100644 index 936fb3f..0000000 --- a/smb4k/smb4ktooltip.cpp +++ /dev/null @@ -1,858 +0,0 @@ -/*************************************************************************** - smb4ktooltip - Provides tooltips for Smb4K - ------------------- - begin : Sa Dez 23 2010 - copyright : (C) 2010-2017 by Alexander Reinholdt - email : alexander.reinholdt@kdemail.net - ***************************************************************************/ - -/*************************************************************************** - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, but * - * WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * - * General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., 51 Franklin Street, Suite 500, Boston,* - * MA 02110-1335, USA * - ***************************************************************************/ - -// application specific includes -#include "smb4ktooltip.h" -#include "core/smb4kbasicnetworkitem.h" -#include "core/smb4kworkgroup.h" -#include "core/smb4khost.h" -#include "core/smb4kshare.h" -#include "core/smb4kglobal.h" - -// Qt includes -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -// KDE includes -#include -#include -#include -#include -#include - -using namespace Smb4KGlobal; - - -Smb4KToolTip::Smb4KToolTip(QWidget* parent) -: QWidget(parent, Qt::ToolTip|Qt::BypassGraphicsProxyWidget|Qt::FramelessWindowHint), - m_item(NetworkItemPtr()), m_tip_layout(0), m_info_layout(0), m_text_layout(0) -{ - qDebug() << "Use KToolTipWidget for the tooltips"; - - m_master_browser_label = 0; - m_comment_label = 0; - m_ip_label = 0; - m_mounted_label = 0; - m_size_label = 0; - - setAttribute(Qt::WA_TranslucentBackground); - - // Copied from QToolTip - setForegroundRole(QPalette::ToolTipText); - setBackgroundRole(QPalette::ToolTipBase); - setPalette(QToolTip::palette()); - ensurePolished(); - setWindowOpacity(style()->styleHint(QStyle::SH_ToolTipLabel_Opacity, 0, this) / 255.0); -} - - -Smb4KToolTip::~Smb4KToolTip() -{ - // Never delete m_item here. We only have a pointer to - // somewhere outside of this class. -} - - -void Smb4KToolTip::setup(Smb4KToolTip::Parent parent, const NetworkItemPtr &item) -{ - if (item) - { - m_item = item; - - // Set up tool tip. - switch (parent) - { - case NetworkBrowser: - { - setupNetworkBrowserToolTip(); - break; - } - case SharesView: - { - setupSharesViewToolTip(); - break; - } - default: - { - return; - } - } - } -} - - -void Smb4KToolTip::update(Smb4KToolTip::Parent parent, const NetworkItemPtr &item) -{ - if (item) - { - m_item = item; - - switch (parent) - { - case NetworkBrowser: - { - switch (m_item->type()) - { - case Workgroup: - { - WorkgroupPtr workgroup = item.staticCast(); - - if (workgroup->hasMasterBrowserIpAddress()) - { - m_master_browser_label->setText(workgroup->masterBrowserName()+" ("+workgroup->masterBrowserIpAddress()+')'); - } - else - { - m_master_browser_label->setText(workgroup->masterBrowserName()); - } - break; - } - case Host: - { - HostPtr host = item.staticCast(); - - if (!host->comment().isEmpty()) - { - m_comment_label->setText(host->comment()); - } - else - { - m_comment_label->setText("-"); - } - - if (host->hasIpAddress()) - { - m_ip_label->setText(host->ipAddress()); - } - else - { - m_ip_label->setText("-"); - } - break; - } - case Share: - { - SharePtr share = item.staticCast(); - - if (!share->comment().isEmpty()) - { - m_comment_label->setText(share->comment()); - } - else - { - m_comment_label->setText("-"); - } - - if (!share->isPrinter()) - { - if (share->isMounted()) - { - m_mounted_label->setText(i18n("yes")); - } - else - { - m_mounted_label->setText(i18n("no")); - } - } - else - { - m_mounted_label->setText("-"); - } - - if (share->hasHostIpAddress()) - { - m_ip_label->setText(share->hostIpAddress()); - } - else - { - m_ip_label->setText("-"); - } - - break; - } - default: - { - break; - } - } - break; - } - case SharesView: - { - SharePtr share = item.staticCast(); - - if (share->totalDiskSpace() != 0 && share->freeDiskSpace() != 0) - { - m_size_label->setText(i18n("%1 of %2 free (%3 used)", - share->freeDiskSpaceString(), - share->totalDiskSpaceString(), - share->diskUsageString())); - } - else - { - m_size_label->setText(i18n("unknown")); - } - break; - } - default: - { - break; - } - } - } -} - - -void Smb4KToolTip::show(const QPoint &pos) -{ - // Get the geometry of the screen where the cursor is - const QRect screenRect = QApplication::screenAt(pos)->geometry(); - - // Adjust the size - adjustSize(); - - // The position where the tooltip is to be shown - QPoint tooltipPos; - - // Correct the position of the tooltip, so that it is completely - // shown. - if (pos.x() + width() + 5 >= screenRect.x() + screenRect.width()) - { - tooltipPos.setX(pos.x() - width() - 5); - } - else - { - tooltipPos.setX(pos.x() + 5); - } - - if (pos.y() + height() + 5 >= screenRect.y() + screenRect.height()) - { - tooltipPos.setY(pos.y() - height() - 5); - } - else - { - tooltipPos.setY(pos.y() + 5); - } - - move(tooltipPos); - setVisible(true); - - QTimer::singleShot(10000, this, SLOT(slotHideToolTip())); -} - - -void Smb4KToolTip::hide() -{ - setVisible(false); -} - - -void Smb4KToolTip::setupNetworkBrowserToolTip() -{ - // NOTE: If you change the layout here, adjust also the update function! - - m_tip_layout = new QHBoxLayout(this); - m_tip_layout->setAlignment(Qt::AlignTop); - m_info_layout = new QVBoxLayout(); - m_info_layout->setAlignment(Qt::AlignTop); - - // Set the icon - QLabel *icon_label = new QLabel(this); - icon_label->setPixmap(m_item->icon().pixmap(KIconLoader::SizeEnormous)); - - m_tip_layout->addWidget(icon_label, Qt::AlignHCenter); - m_tip_layout->addLayout(m_info_layout); - - // Use a brighter color for the left label. This was copied from - // KFileMetaDataWidget class. - QPalette p = palette(); - const QPalette::ColorRole role = foregroundRole(); - QColor textColor = p.color(role); - textColor.setAlpha(128); - p.setColor(role, textColor); - - // FIXME: Use smaller font for the information. Get the current - // point size of the window system with QFontInfo::pointSize(). - - switch (m_item->type()) - { - case Workgroup: - { - WorkgroupPtr workgroup = m_item.staticCast(); - - QLabel *caption = new QLabel(workgroup->workgroupName(), this); - caption->setAlignment(Qt::AlignHCenter); - QFont caption_font = caption->font(); - caption_font.setBold(true); - caption->setFont(caption_font); - - m_info_layout->addWidget(caption); - m_info_layout->addWidget(new KSeparator(this), Qt::AlignHCenter); - - m_text_layout = new QGridLayout(); - - QLabel *type_label = new QLabel(i18n("Type"), this); - type_label->setPalette(p); - - m_text_layout->addWidget(type_label, 0, 0, Qt::AlignRight); - m_text_layout->addWidget(new QLabel(i18n("Workgroup"), this), 0, 1, 0); - - QLabel *mb_label = new QLabel(i18n("Master browser"), this); - mb_label->setPalette(p); - - m_text_layout->addWidget(mb_label, 1, 0, Qt::AlignRight); - - if (workgroup->hasMasterBrowserIpAddress()) - { - m_master_browser_label = new QLabel(workgroup->masterBrowserName()+" ("+workgroup->masterBrowserIpAddress()+')', this); - m_text_layout->addWidget(m_master_browser_label, 1, 1, 0); - } - else - { - m_master_browser_label = new QLabel(workgroup->masterBrowserName(), this); - m_text_layout->addWidget(m_master_browser_label, 1, 1, 0); - } - - m_info_layout->addLayout(m_text_layout); - m_info_layout->addSpacerItem(new QSpacerItem(0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding)); - break; - } - case Host: - { - HostPtr host = m_item.staticCast(); - - QLabel *caption = new QLabel(host->hostName(), this); - caption->setAlignment(Qt::AlignHCenter); - QFont caption_font = caption->font(); - caption_font.setBold(true); - caption->setFont(caption_font); - - m_info_layout->addWidget(caption, Qt::AlignHCenter); - m_info_layout->addWidget(new KSeparator(this), Qt::AlignHCenter); - - m_text_layout = new QGridLayout(); - - QLabel *type_label = new QLabel(i18n("Type"), this); - type_label->setPalette(p); - - m_text_layout->addWidget(type_label, 0, 0, Qt::AlignRight); - m_text_layout->addWidget(new QLabel(i18n("Host"), this), 0, 1, 0); - - QLabel *co_label = new QLabel(i18n("Comment"), this); - co_label->setPalette(p); - - m_text_layout->addWidget(co_label, 1, 0, Qt::AlignRight); - - if (!host->comment().isEmpty()) - { - m_comment_label = new QLabel(host->comment(), this); - m_text_layout->addWidget(m_comment_label, 1, 1, 0); - } - else - { - m_comment_label = new QLabel("-", this); - m_text_layout->addWidget(m_comment_label, 1, 1, 0); - } - - QLabel *ip_label = new QLabel(i18n("IP Address"), this); - ip_label->setPalette(p); - - m_text_layout->addWidget(ip_label, 2, 0, Qt::AlignRight); - - if (host->hasIpAddress()) - { - m_ip_label = new QLabel(host->ipAddress(), this); - m_text_layout->addWidget(m_ip_label, 2, 1, 0); - } - else - { - m_ip_label = new QLabel("-", this); - m_text_layout->addWidget(m_ip_label, 2, 1, 0); - } - - QLabel *wg_label = new QLabel(i18n("Workgroup"), this); - wg_label->setPalette(p); - - m_text_layout->addWidget(wg_label, 3, 0, Qt::AlignRight); - m_text_layout->addWidget(new QLabel(host->workgroupName(), this), 3, 1, 0); - - m_info_layout->addLayout(m_text_layout); - m_info_layout->addSpacerItem(new QSpacerItem(0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding)); - break; - } - case Share: - { - SharePtr share = m_item.staticCast(); - - QLabel *caption = new QLabel(share->shareName(), this); - caption->setAlignment(Qt::AlignHCenter); - QFont caption_font = caption->font(); - caption_font.setBold(true); - caption->setFont(caption_font); - - m_info_layout->addWidget(caption); - m_info_layout->addWidget(new KSeparator(this), Qt::AlignHCenter); - - m_text_layout = new QGridLayout(); - - QLabel *type_label = new QLabel(i18n("Type"), this); - type_label->setPalette(p); - - m_text_layout->addWidget(type_label, 0, 0, Qt::AlignRight); - m_text_layout->addWidget(new QLabel(i18n("Share (%1)", share->shareTypeString()), this), 0, 1, 0); - - QLabel *co_label = new QLabel(i18n("Comment"), this); - co_label->setPalette(p); - - m_text_layout->addWidget(co_label, 1, 0, Qt::AlignRight); - - if (!share->comment().isEmpty()) - { - m_comment_label = new QLabel(share->comment(), this); - m_text_layout->addWidget(m_comment_label, 1, 1, 0); - } - else - { - m_comment_label = new QLabel("-", this); - m_text_layout->addWidget(m_comment_label, 1, 1, 0); - } - - QLabel *mnt_label = new QLabel(i18n("Mounted"), this); - mnt_label->setPalette(p); - - m_text_layout->addWidget(mnt_label, 2, 0, Qt::AlignRight); - - if (!share->isPrinter()) - { - if (share->isMounted()) - { - m_mounted_label = new QLabel(i18n("yes"), this); - m_text_layout->addWidget(m_mounted_label, 2, 1, 0); - } - else - { - m_mounted_label = new QLabel(i18n("no"), this); - m_text_layout->addWidget(m_mounted_label, 2, 1, 0); - } - } - else - { - m_mounted_label = new QLabel("-", this); - m_text_layout->addWidget(m_mounted_label, 2, 1, 0); - } - - QLabel *h_label = new QLabel(i18n("Host"), this); - h_label->setPalette(p); - - m_text_layout->addWidget(h_label, 3, 0, Qt::AlignRight); - m_text_layout->addWidget(new QLabel(share->hostName()), 3, 1, 0); - - QLabel *ip_label = new QLabel(i18n("IP Address"), this); - ip_label->setPalette(p); - - m_text_layout->addWidget(ip_label, 4, 0, Qt::AlignRight); - - if (share->hasHostIpAddress()) - { - m_ip_label = new QLabel(share->hostIpAddress(), this); - m_text_layout->addWidget(m_ip_label, 4, 1, 0); - } - else - { - m_ip_label = new QLabel("-", this); - m_text_layout->addWidget(m_ip_label, 4, 1, 0); - } - - QLabel *unc_label = new QLabel(i18n("Location"), this); - unc_label->setPalette(p); - - m_text_layout->addWidget(unc_label, 5, 0, Qt::AlignRight); - m_text_layout->addWidget(new QLabel(share->displayString(), this), 5, 1, 0); - - m_info_layout->addLayout(m_text_layout); - m_info_layout->addSpacerItem(new QSpacerItem(0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding)); - break; - } - default: - { - return; - } - } - - adjustSize(); -} - - -void Smb4KToolTip::setupSharesViewToolTip() -{ - // NOTE: If you change the layout here, adjust also the update function! - - SharePtr share = m_item.staticCast(); - - m_tip_layout = new QHBoxLayout(this); - m_tip_layout->setAlignment(Qt::AlignTop); - m_info_layout = new QVBoxLayout(); - m_info_layout->setAlignment(Qt::AlignTop); - - // Set the icon - QLabel *icon_label = new QLabel(this); - icon_label->setPixmap(share->icon().pixmap(KIconLoader::SizeEnormous)); - - m_tip_layout->addWidget(icon_label, Qt::AlignHCenter); - m_tip_layout->addLayout(m_info_layout); - - // Use a brighter color for the left label. This was copied from - // KFileMetaDataWidget class. - QPalette p = palette(); - const QPalette::ColorRole role = foregroundRole(); - QColor textColor = p.color(role); - textColor.setAlpha(128); - p.setColor(role, textColor); - - // FIXME: Use smaller font for the information. Get the current - // point size of the window system with QFontInfo::pointSize(). - - QLabel *caption = new QLabel(share->shareName(), this); - caption->setAlignment(Qt::AlignHCenter); - QFont caption_font = caption->font(); - caption_font.setBold(true); - caption->setFont(caption_font); - - m_info_layout->addWidget(caption); - m_info_layout->addWidget(new KSeparator(this), Qt::AlignHCenter); - - m_text_layout = new QGridLayout(); - - QLabel *unc_label = new QLabel(i18n("Location"), this); - unc_label->setPalette(p); - - m_text_layout->addWidget(unc_label, 0, 0, Qt::AlignRight); - m_text_layout->addWidget(new QLabel(share->displayString(), this), 0, 1, 0); - - QLabel *mp_label = new QLabel(i18n("Mountpoint"), this); - mp_label->setPalette(p); - - m_text_layout->addWidget(mp_label, 1, 0, Qt::AlignRight); - m_text_layout->addWidget(new QLabel(share->path(), this), 1, 1, 0); - - QLabel *log_label = new QLabel(i18n("Login"), this); - log_label->setPalette(p); - - m_text_layout->addWidget(log_label, 2, 0, Qt::AlignRight); - - if (!share->login().isEmpty()) - { - m_text_layout->addWidget(new QLabel(share->login(), this), 2, 1, 0); - } - else - { - m_text_layout->addWidget(new QLabel(i18n("unknown"), this), 2, 1, 0); - } - - QLabel *own_label = new QLabel(i18n("Owner"), this); - own_label->setPalette(p); - - m_text_layout->addWidget(own_label, 3, 0, Qt::AlignRight); - - QString owner = (!share->user().loginName().isEmpty() ? share->user().loginName() : i18n("unknown")); - QString group = (!share->group().name().isEmpty() ? share->group().name() : i18n("unknown")); - - m_text_layout->addWidget(new QLabel(QString("%1 - %2") - .arg(owner).arg(group), this), 3, 1, 0); - - QLabel *fs_label = new QLabel(i18n("File system"), this); - fs_label->setPalette(p); - - m_text_layout->addWidget(fs_label, 4, 0, Qt::AlignRight); - m_text_layout->addWidget(new QLabel(share->fileSystemString()), 4, 1, 0); - - QLabel *s_label = new QLabel(i18n("Size"), this); - s_label->setPalette(p); - - m_text_layout->addWidget(s_label, 5, 0, Qt::AlignRight); - - if (share->totalDiskSpace() != 0 && share->freeDiskSpace() != 0) - { - m_size_label = new QLabel(i18n("%1 free of %2 (%3 used)", - share->freeDiskSpaceString(), - share->totalDiskSpaceString(), - share->diskUsageString())); - m_text_layout->addWidget(m_size_label, 5, 1, 0); - } - else - { - m_size_label = new QLabel(i18n("unknown")); - m_text_layout->addWidget(m_size_label, 5, 1, 0); - } - - m_info_layout->addLayout(m_text_layout); - m_info_layout->addSpacerItem(new QSpacerItem(0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding)); -} - - -void Smb4KToolTip::updateNetworkBrowserToolTip() -{ - if (m_item && m_text_layout && m_tip_layout) - { - switch (m_item->type()) - { - case Workgroup: - { - WorkgroupPtr workgroup = m_item.staticCast(); - - // Master browser name and IP address - QLayoutItem *mb_item = m_text_layout->itemAtPosition(1, 1); - QLabel *mb_label = static_cast(mb_item->widget()); - - if (mb_label) - { - if (!workgroup->hasMasterBrowserIpAddress()) - { - mb_label->setText(workgroup->masterBrowserName()+" ("+workgroup->masterBrowserIpAddress()+')'); - } - else - { - mb_label->setText(workgroup->masterBrowserName()); - } - } - - break; - } - case Host: - { - HostPtr host = m_item.staticCast(); - - // Comment - QLayoutItem *co_item = m_text_layout->itemAtPosition(1, 1); - QLabel *co_label = static_cast(co_item->widget()); - - if (co_label) - { - if (!host->comment().isEmpty()) - { - co_label->setText(host->comment()); - } - else - { - co_label->setText("-"); - } - } - - // IP address - QLayoutItem *ip_item = m_text_layout->itemAtPosition(2, 1); - QLabel *ip_label = static_cast(ip_item->widget()); - - if (ip_label) - { - if (host->hasIpAddress()) - { - ip_label->setText(host->ipAddress()); - } - else - { - ip_label->setText("-"); - } - } - - break; - } - case Share: - { - SharePtr share = m_item.staticCast(); - - // Icon - QLayoutItem *icon_item = m_tip_layout->itemAt(0); - QLabel *icon_label = static_cast(icon_item->widget()); - icon_label->setPixmap(m_item->icon().pixmap(KIconLoader::SizeEnormous)); - - // Comment - QLayoutItem *co_item = m_text_layout->itemAtPosition(1, 1); - QLabel *co_label = static_cast(co_item->widget()); - - if (co_label) - { - if (!share->comment().isEmpty()) - { - co_label->setText(share->comment()); - } - else - { - co_label->setText("-"); - } - } - - // Mounted indicator - QLayoutItem *mnt_item = m_text_layout->itemAtPosition(2, 1); - QLabel *mnt_label = static_cast(mnt_item->widget()); - - if (mnt_label) - { - if (!share->isPrinter()) - { - if (share->isMounted()) - { - mnt_label->setText(i18n("yes")); - } - else - { - mnt_label->setText(i18n("no")); - } - } - else - { - mnt_label->setText("-"); - } - } - - // The rest won't change while the tool tip is shown. - - break; - } - default: - { - break; - } - } - } -} - - -void Smb4KToolTip::updateSharesViewToolTip() -{ - if (m_item && m_text_layout && m_tip_layout) - { - SharePtr share = m_item.staticCast(); - - // Set the icon - QLayoutItem *icon_item = m_tip_layout->itemAt(0); - QLabel *icon_label = static_cast(icon_item->widget()); - icon_label->setPixmap(m_item->icon().pixmap(KIconLoader::SizeEnormous)); - - QLayoutItem *log_item = m_text_layout->itemAtPosition(2, 1); - QLabel *log_label = static_cast(log_item->widget()); - - if (!share->login().isEmpty()) - { - log_label->setText(share->login()); - } - else - { - log_label->setText(i18n("unknown")); - } - - QLayoutItem *s_item = m_text_layout->itemAtPosition(5, 1); - QLabel *s_label = static_cast(s_item->widget()); - - if (share->totalDiskSpace() != 0 && share->freeDiskSpace() != 0) - { - s_label->setText(i18n("%1 free of %2 (%3 used)", - share->freeDiskSpaceString(), - share->totalDiskSpaceString(), - share->diskUsageString())); - } - else - { - s_label->setText(i18n("unknown")); - } - } - - // The rest won't change while the tool tip is shown. -} - - -void Smb4KToolTip::paintEvent(QPaintEvent *e) -{ - // Copied from Dolphin's meta data tool tips. - Q_UNUSED(e); - - QPainter painter(this); - - QColor toColor = palette().brush(QPalette::ToolTipBase).color(); - QColor fromColor = KColorScheme::shade(toColor, KColorScheme::LightShade, 0.2); - - const bool haveAlphaChannel = KWindowSystem::compositingActive(); - - if (haveAlphaChannel) - { - painter.setRenderHint(QPainter::Antialiasing); - painter.translate(0.5, 0.5); - toColor.setAlpha(220); - fromColor.setAlpha(220); - } - - QLinearGradient gradient(QPointF(0.0, 0.0), QPointF(0.0, height())); - gradient.setColorAt(0.0, fromColor); - gradient.setColorAt(1.0, toColor); - painter.setPen(Qt::NoPen); - painter.setBrush(gradient); - - const QRect rect(0, 0, width(), height()); - - if (haveAlphaChannel) - { - const qreal radius = 5.0; - - QPainterPath path; - path.moveTo(rect.left(), rect.top() + radius); - arc(path, rect.left() + radius, rect.top() + radius, radius, 180, -90); - arc(path, rect.right() - radius, rect.top() + radius, radius, 90, -90); - arc(path, rect.right() - radius, rect.bottom() - radius, radius, 0, -90); - arc(path, rect.left() + radius, rect.bottom() - radius, radius, 270, -90); - path.closeSubpath(); - - painter.drawPath(path); - } - else - { - painter.drawRect(rect); - } -} - - -void Smb4KToolTip::arc(QPainterPath& path, - qreal cx, qreal cy, - qreal radius, qreal angle, - qreal sweepLength) -{ - // Copied from Dolphin's meta data tool tips. - path.arcTo(cx-radius, cy-radius, radius * 2, radius * 2, angle, sweepLength); -} - - -void Smb4KToolTip::slotHideToolTip() -{ - hide(); -} - diff --git a/smb4k/smb4ktooltip.h b/smb4k/smb4ktooltip.h deleted file mode 100644 index 8c7e352..0000000 --- a/smb4k/smb4ktooltip.h +++ /dev/null @@ -1,87 +0,0 @@ -/*************************************************************************** - smb4ktooltip - Provides tooltips for Smb4K - ------------------- - begin : Sa Dez 23 2010 - copyright : (C) 2010-2017 by Alexander Reinholdt - email : alexander.reinholdt@kdemail.net - ***************************************************************************/ - -/*************************************************************************** - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, but * - * WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * - * General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., 51 Franklin Street, Suite 500, Boston,* - * MA 02110-1335, USA * - ***************************************************************************/ - -#ifndef SMB4KTOOLTIP_H -#define SMB4KTOOLTIP_H - -// application specific includes -#include "core/smb4kglobal.h" - -// Qt includes -#include -#include -#include -#include -#include -#include - -// forward declarations -class Smb4KBasicNetworkItem; - -class Q_DECL_EXPORT Smb4KToolTip : public QWidget -{ - Q_OBJECT - - public: - enum Parent { - NetworkBrowser, - SharesView, - UnknownParent - }; - explicit Smb4KToolTip(QWidget *parent = 0); - ~Smb4KToolTip(); - void setup(Parent parent, const NetworkItemPtr &item); - void update(Parent parent, const NetworkItemPtr &item); - void show(const QPoint &pos); - void hide(); - const NetworkItemPtr &networkItem() { return m_item; } - - protected: - void paintEvent(QPaintEvent *e) override; - - protected slots: - void slotHideToolTip(); - - private: - NetworkItemPtr m_item; - QHBoxLayout *m_tip_layout; - QVBoxLayout *m_info_layout; - QGridLayout *m_text_layout; - void setupNetworkBrowserToolTip(); - void updateNetworkBrowserToolTip(); - void setupSharesViewToolTip(); - void updateSharesViewToolTip(); - static void arc(QPainterPath& path, - qreal cx, qreal cy, - qreal radius, qreal angle, - qreal sweepLength); - QLabel *m_master_browser_label; - QLabel *m_comment_label; - QLabel *m_ip_label; - QLabel *m_mounted_label; - QLabel *m_size_label; -}; - -#endif