8#include "kurlnavigatorschemecombo_p.h"
14#include <QStyleOption>
16#include <KLocalizedString>
17#include <kprotocolinfo.h>
18#include <kprotocolmanager.h>
19#include <kurlnavigator.h>
23const int ArrowSize = 10;
29 : KUrlNavigatorButtonBase(parent)
34 m_menu =
new QMenu(
this);
40void KUrlNavigatorSchemeCombo::setSupportedSchemes(
const QStringList &schemes)
45 for (
const QString &scheme : schemes) {
46 QAction *action = m_menu->addAction(scheme);
51QSize KUrlNavigatorSchemeCombo::sizeHint()
const
53 const QSize size = KUrlNavigatorButtonBase::sizeHint();
56 width += (3 * BorderWidth) + ArrowSize;
61void KUrlNavigatorSchemeCombo::setScheme(
const QString &scheme)
66QString KUrlNavigatorSchemeCombo::currentScheme()
const
71void KUrlNavigatorSchemeCombo::showEvent(
QShowEvent *event)
73 KUrlNavigatorButtonBase::showEvent(event);
74 if (!
event->spontaneous() && m_schemes.isEmpty()) {
77 auto it = std::remove_if(m_schemes.begin(), m_schemes.end(), [](
const QString &s) {
80 return !KProtocolManager::supportsListing(url);
82 m_schemes.erase(it, m_schemes.end());
84 std::sort(m_schemes.begin(), m_schemes.end());
90void KUrlNavigatorSchemeCombo::paintEvent(
QPaintEvent *event)
95 const int buttonWidth = width();
96 const int buttonHeight = height();
98 drawHoverBackground(&painter);
100 const QColor fgColor = foregroundColor();
101 painter.setPen(fgColor);
104 const int arrowX = buttonWidth - ArrowSize - BorderWidth;
105 const int arrowY = (buttonHeight - ArrowSize) / 2;
108 option.rect =
QRect(arrowX, arrowY, ArrowSize, ArrowSize);
109 option.palette = palette();
116 const int textWidth = arrowX - (2 * BorderWidth);
121 style()->drawItemText(&painter,
QRect(BorderWidth, 0, textWidth, buttonHeight), alignment, option.palette, isEnabled(), text());
124void KUrlNavigatorSchemeCombo::setSchemeFromMenu(
QAction *action)
128 Q_EMIT activated(scheme);
131void KUrlNavigatorSchemeCombo::updateMenu()
133 initializeCategories();
134 std::sort(m_schemes.begin(), m_schemes.end());
138 for (
const QString &scheme : std::as_const(m_schemes)) {
139 if (m_categories.contains(scheme)) {
140 const SchemeCategory
category = m_categories.value(scheme);
143 items[OtherCategory].
append(scheme);
150 QMenu *menu = m_menu;
152 if (!items[category].isEmpty()) {
154 case DevicesCategory:
155 menu = m_menu->
addMenu(
i18nc(
"@item:inmenu",
"Devices"));
158 case SubversionCategory:
159 menu = m_menu->
addMenu(
i18nc(
"@item:inmenu",
"Subversion"));
172 for (
const QString &scheme : std::as_const(items[category])) {
177 if (menu == m_menu) {
184void KUrlNavigatorSchemeCombo::initializeCategories()
186 if (m_categories.isEmpty()) {
187 m_categories.insert(QStringLiteral(
"file"), CoreCategory);
188 m_categories.insert(QStringLiteral(
"ftp"), CoreCategory);
189 m_categories.insert(QStringLiteral(
"fish"), CoreCategory);
190 m_categories.insert(QStringLiteral(
"nfs"), CoreCategory);
191 m_categories.insert(QStringLiteral(
"sftp"), CoreCategory);
192 m_categories.insert(QStringLiteral(
"smb"), CoreCategory);
193 m_categories.insert(QStringLiteral(
"webdav"), CoreCategory);
195 m_categories.insert(QStringLiteral(
"desktop"), PlacesCategory);
196 m_categories.insert(QStringLiteral(
"fonts"), PlacesCategory);
197 m_categories.insert(QStringLiteral(
"programs"), PlacesCategory);
198 m_categories.insert(QStringLiteral(
"settings"), PlacesCategory);
199 m_categories.insert(QStringLiteral(
"trash"), PlacesCategory);
201 m_categories.insert(QStringLiteral(
"floppy"), DevicesCategory);
202 m_categories.insert(QStringLiteral(
"camera"), DevicesCategory);
203 m_categories.insert(QStringLiteral(
"remote"), DevicesCategory);
205 m_categories.insert(QStringLiteral(
"svn"), SubversionCategory);
206 m_categories.insert(QStringLiteral(
"svn+file"), SubversionCategory);
207 m_categories.insert(QStringLiteral(
"svn+http"), SubversionCategory);
208 m_categories.insert(QStringLiteral(
"svn+https"), SubversionCategory);
209 m_categories.insert(QStringLiteral(
"svn+ssh"), SubversionCategory);
215#include "moc_kurlnavigatorschemecombo_p.cpp"
static QString removeAcceleratorMarker(const QString &label)
static QStringList protocols()
Returns list of all known protocols.
Widget that allows to navigate through the paths of an URL.
QString i18nc(const char *context, const char *text, const TYPE &arg...)
AKONADI_CALENDAR_EXPORT KCalendarCore::Event::Ptr event(const Akonadi::Item &item)
Category category(StandardShortcut id)
QVariant data() const const
void setData(const QVariant &data)
void append(QList< T > &&value)
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
QString toString() const const