23 #include <QtGui/QAction>
24 #include <QtGui/QMenu>
25 #include <QtGui/QPainter>
26 #include <QtGui/QPaintEvent>
27 #include <QtGui/QStyleOption>
36 const int ArrowSize = 10;
48 m_menu =
new QMenu(
this);
56 m_protocols = protocols;
59 foreach (
const QString& protocol, protocols) {
60 QAction* action = m_menu->addAction(protocol);
61 action->setData(protocol);
67 const QSize size = KUrlNavigatorButtonBase::sizeHint();
69 QFontMetrics fontMetrics(font());
73 return QSize(width, size.height());
88 KUrlNavigatorButtonBase::showEvent(event);
89 if (!event->spontaneous() && m_protocols.isEmpty()) {
93 QStringList::iterator it = m_protocols.begin();
94 while (it != m_protocols.end()) {
95 const KUrl url(*it +
"://");
97 it = m_protocols.erase(it);
111 QPainter painter(
this);
112 const int buttonWidth = width();
113 const int buttonHeight = height();
118 painter.setPen(fgColor);
121 const int arrowX = buttonWidth - ArrowSize -
BorderWidth;
122 const int arrowY = (buttonHeight - ArrowSize) / 2;
125 option.rect =
QRect(arrowX, arrowY, ArrowSize, ArrowSize);
126 option.palette = palette();
127 option.palette.setColor(QPalette::Text, fgColor);
128 option.palette.setColor(QPalette::WindowText, fgColor);
129 option.palette.setColor(QPalette::ButtonText, fgColor);
130 style()->drawPrimitive(QStyle::PE_IndicatorArrowDown, &option, &painter,
this );
134 int alignment = Qt::AlignCenter | Qt::TextShowMnemonic;
135 if (!style()->styleHint(QStyle::SH_UnderlineShortcut, &option,
this)) {
136 alignment |= Qt::TextHideMnemonic;
138 style()->drawItemText(&painter,
QRect(BorderWidth, 0, textWidth, buttonHeight),
139 alignment, option.palette, isEnabled(), text());
144 const QString protocol = action->data().toString();
149 void KUrlNavigatorProtocolCombo::updateMenu()
151 initializeCategories();
156 foreach (
const QString& protocol, m_protocols) {
157 if (m_categories.contains(protocol)) {
158 const ProtocolCategory category = m_categories.value(protocol);
159 items[category].append(protocol);
161 items[OtherCategory].append(protocol);
168 QMenu* menu = m_menu;
169 for (
int category = 0; category < CategoryCount; ++category) {
170 if (items[category].count() > 0) {
172 case DevicesCategory:
173 menu = m_menu->addMenu(
i18nc(
"@item:inmenu",
"Devices"));
176 case SubversionCategory:
177 menu = m_menu->addMenu(
i18nc(
"@item:inmenu",
"Subversion"));
181 menu = m_menu->addMenu(
i18nc(
"@item:inmenu",
"Other"));
190 foreach (
const QString& protocol, items[category]) {
191 QAction* action = menu->addAction(protocol);
192 action->setData(protocol);
195 if (menu == m_menu) {
196 menu->addSeparator();
202 void KUrlNavigatorProtocolCombo::initializeCategories()
204 if (m_categories.isEmpty()) {
205 m_categories.insert(
"file", CoreCategory);
206 m_categories.insert(
"ftp", CoreCategory);
207 m_categories.insert(
"fish", CoreCategory);
208 m_categories.insert(
"nfs", CoreCategory);
209 m_categories.insert(
"sftp", CoreCategory);
210 m_categories.insert(
"smb", CoreCategory);
211 m_categories.insert(
"webdav", CoreCategory);
213 m_categories.insert(
"desktop", PlacesCategory);
214 m_categories.insert(
"fonts", PlacesCategory);
215 m_categories.insert(
"programs", PlacesCategory);
216 m_categories.insert(
"settings", PlacesCategory);
217 m_categories.insert(
"trash", PlacesCategory);
219 m_categories.insert(
"floppy", DevicesCategory);
220 m_categories.insert(
"camera", DevicesCategory);
221 m_categories.insert(
"remote", DevicesCategory);
223 m_categories.insert(
"svn", SubversionCategory);
224 m_categories.insert(
"svn+file", SubversionCategory);
225 m_categories.insert(
"svn+http", SubversionCategory);
226 m_categories.insert(
"svn+https", SubversionCategory);
227 m_categories.insert(
"svn+ssh", SubversionCategory);
233 #include "kurlnavigatorprotocolcombo_p.moc"
static QStringList protocols()
void setCustomProtocols(const QStringList &protocols)
void activated(const QString &protocol)
QString removeAcceleratorMarker(const QString &label_)
QString i18nc(const char *ctxt, const char *text)
virtual void paintEvent(QPaintEvent *event)
virtual QSize sizeHint() const
KUrlNavigatorProtocolCombo(const QString &protocol, QWidget *parent=0)
void setProtocol(const QString &protocol)
virtual void showEvent(QShowEvent *event)
QString currentProtocol() const
static bool supportsListing(const KUrl &url)