21 #include <tqapplication.h>
22 #include <tqcheckbox.h>
23 #include <tqdrawutil.h>
24 #include <tqfontmetrics.h>
27 #include <tqpainter.h>
28 #include <tqpopupmenu.h>
31 #include <tqwhatsthis.h>
33 #include <tdeaboutdata.h>
34 #include <tdeconfig.h>
36 #include <tdeglobal.h>
37 #include <kicondialog.h>
38 #include <kiconloader.h>
39 #include <kinstance.h>
40 #include <klineedit.h>
41 #include <tdelocale.h>
42 #include <kmimetype.h>
43 #include <kprotocolinfo.h>
44 #include <kstringhandler.h>
46 #include <kurlrequester.h>
47 #include <tdeio/global.h>
48 #include <tdeio/netaccess.h>
56 class KURLBarToolTip :
public TQToolTip
59 KURLBarToolTip( TQListBox *view ) : TQToolTip( view ), m_view( view ) {}
62 virtual void maybeTip(
const TQPoint& point ) {
63 TQListBoxItem *item = m_view->itemAt( point );
65 TQString text =
static_cast<KURLBarItem*
>( item )->toolTip();
66 if ( !text.isEmpty() )
67 tip( m_view->itemRect( item ), text );
79 class KURLBarItem::KURLBarItemPrivate
91 const KURL& url,
bool persistent,
const TQString& description,
92 const TQString& icon, TDEIcon::Group group )
93 : TQListBoxPixmap( TDEIconLoader::unknown() ),
103 const KURL& url,
const TQString& description,
104 const TQString& icon, TDEIcon::Group group )
105 : TQListBoxPixmap( TDEIconLoader::unknown() ),
114 void KURLBarItem::init(
const TQString& icon, TDEIcon::Group group,
115 const TQString& description,
bool persistent )
117 d =
new KURLBarItemPrivate;
118 d->isPersistent = persistent;
120 setCustomHighlighting(
true );
133 if ( m_description.isEmpty() )
134 setText(
url.fileName() );
142 if (
icon.isEmpty() )
143 m_pixmap = KMimeType::pixmapForURL( m_url, 0, group, iconSize() );
145 m_pixmap = TDEGlobal::iconLoader()->loadIcon(
icon, group, iconSize(),
146 TDEIcon::DefaultState );
151 m_description = desc;
152 setText( desc.isEmpty() ? m_url.fileName() : desc );
159 kdWarning() <<
"KURLBar: dynamic (non-persistent) items can not be global." << endl;
173 return m_toolTip.isEmpty() ? m_url.prettyURL() : m_toolTip;
176 int KURLBarItem::iconSize()
const
181 void KURLBarItem::paint( TQPainter *p )
183 TQListBox *box = listBox();
184 int w =
width( box );
185 static const int margin = KDialog::spacingHint();
188 if ( isCurrent() || isSelected() ) {
191 TQBrush brush = box->colorGroup().brush( TQColorGroup::Highlight );
192 p->fillRect( 0, 0, w, h, brush );
193 TQPen pen = p->pen();
195 pen.setColor( box->colorGroup().mid() );
198 p->drawPoint( 0, 0 );
199 p->drawPoint( 0, h - 1 );
200 p->drawPoint( w - 1, 0 );
201 p->drawPoint( w - 1, h - 1 );
206 if ( m_parent->
iconSize() < TDEIcon::SizeMedium ) {
211 const TQPixmap *pm =
pixmap();
212 int yPos = TQMAX( 0, (
height(box) - pm->height())/2 );
214 p->drawPixmap( margin, yPos, *pm );
215 if ( !text().isEmpty() ) {
216 TQFontMetrics fm = p->fontMetrics();
217 if ( pm->height() < fm.height() ) {
218 yPos = fm.ascent() + fm.leading()/2;
221 yPos =
height(box)/2 - fm.height()/2 + fm.ascent() - margin;
225 int stringWidth = box->width() - pm->width() - 2 - (margin * 2);
226 TQString visibleText = KStringHandler::rPixelSqueeze( text(), fm, stringWidth );
227 int xPos = pm->width() + margin + 2;
229 if ( isCurrent() || isSelected() ) {
230 p->setPen( box->colorGroup().highlight().dark(115) );
231 p->drawText( xPos + ( TQApplication::reverseLayout() ? -1 : 1),
232 yPos + 1, visibleText );
233 p->setPen( box->colorGroup().highlightedText() );
236 p->drawText( xPos, yPos, visibleText );
244 const TQPixmap *pm =
pixmap();
246 if ( !pm->isNull() ) {
247 int x = (w - pm->width()) / 2;
248 x = TQMAX( x, margin );
249 p->drawPixmap( x, y, *pm );
252 if ( !text().isEmpty() ) {
253 TQFontMetrics fm = p->fontMetrics();
254 y += pm->height() + fm.height() - fm.descent();
256 int stringWidth = box->width() - (margin * 2);
257 TQString visibleText = KStringHandler::rPixelSqueeze( text(), fm, stringWidth );
258 int x = (w - fm.width( visibleText )) / 2;
259 x = TQMAX( x, margin );
261 if ( isCurrent() || isSelected() ) {
262 p->setPen( box->colorGroup().highlight().dark(115) );
263 p->drawText( x + ( TQApplication::reverseLayout() ? -1 : 1),
264 y + 1, visibleText );
265 p->setPen( box->colorGroup().highlightedText() );
268 p->drawText( x, y, visibleText );
279 if ( m_parent->
iconSize() < TDEIcon::SizeMedium ) {
280 wmin = TQListBoxPixmap::width( lb ) + KDialog::spacingHint() * 2;
281 hmin = TQListBoxPixmap::height( lb ) + KDialog::spacingHint() * 2;
284 wmin = TQMAX(lb->fontMetrics().width(text()),
pixmap()->
width()) + KDialog::spacingHint() * 2;
285 hmin = lb->fontMetrics().lineSpacing() +
pixmap()->height() + KDialog::spacingHint() * 2;
288 if ( lb->isVertical() )
289 wmin = TQMIN( wmin, lb->viewport()->sizeHint().width() );
291 hmin = TQMIN( hmin, lb->viewport()->sizeHint().height() );
293 return TQSize( wmin, hmin );
314 return d->isPersistent;
320 class KURLBar::KURLBarPrivate
335 : TQFrame( parent, name, f ),
337 m_useGlobal( useGlobalItems ),
338 m_isModified( false ),
339 m_isImmutable( false ),
341 m_iconSize( TDEIcon::SizeMedium )
343 d =
new KURLBarPrivate();
347 TQSizePolicy::Maximum :
348 TQSizePolicy::Preferred,
350 TQSizePolicy::Preferred :
351 TQSizePolicy::Maximum ));
352 TQWhatsThis::add(
this, i18n(
"<qt>The <b>Quick Access</b> panel provides easy access to commonly used file locations.<p>"
353 "Clicking on one of the shortcut entries will take you to that location.<p>"
354 "By right clicking on an entry you can add, edit and remove shortcuts.</qt>"));
363 bool applicationLocal,
364 const TQString& icon, TDEIcon::Group group )
368 m_listBox->insertItem( item );
373 const TQString& icon, TDEIcon::Group group )
376 m_listBox->insertItem( item );
384 TQSizePolicy::Maximum :
385 TQSizePolicy::Preferred,
387 TQSizePolicy::Preferred :
388 TQSizePolicy::Maximum ));
406 if ( m_listBox->parentWidget() !=
this )
407 m_listBox->reparent(
this, TQPoint(0,0) );
408 m_listBox->resize( width(), height() );
411 m_listBox->setSelectionMode( TDEListBox::Single );
412 paletteChange( palette() );
413 m_listBox->setFocusPolicy( TQWidget::TabFocus );
415 connect( m_listBox, TQ_SIGNAL( mouseButtonClicked(
int, TQListBoxItem *,
const TQPoint & ) ),
417 connect( m_listBox, TQ_SIGNAL( dropped( TQDropEvent * )),
419 connect( m_listBox, TQ_SIGNAL( contextMenuRequested( TQListBoxItem *,
422 connect( m_listBox, TQ_SIGNAL( returnPressed( TQListBoxItem * ) ),
428 if ( size == m_iconSize )
449 void KURLBar::resizeEvent( TQResizeEvent *e )
451 TQFrame::resizeEvent( e );
452 m_listBox->resize( width(), height() );
455 void KURLBar::paletteChange(
const TQPalette & )
457 TQPalette pal = palette();
458 TQColor gray = pal.color( TQPalette::Active, TQColorGroup::Background );
459 TQColor selectedTextColor = pal.color( TQPalette::Active, TQColorGroup::BrightText );
460 TQColor foreground = pal.color( TQPalette::Active, TQColorGroup::Foreground );
461 pal.setColor( TQPalette::Active, TQColorGroup::Base, gray );
462 pal.setColor( TQPalette::Active, TQColorGroup::HighlightedText, selectedTextColor );
463 pal.setColor( TQPalette::Active, TQColorGroup::Text, foreground );
464 pal.setColor( TQPalette::Inactive, TQColorGroup::Base, gray );
465 pal.setColor( TQPalette::Inactive, TQColorGroup::HighlightedText, selectedTextColor );
466 pal.setColor( TQPalette::Inactive, TQColorGroup::Text, foreground );
473 return m_listBox->sizeHint();
485 for ( item =
static_cast<KURLBarItem*
>( m_listBox->firstItem() );
487 item =
static_cast<KURLBarItem*
>( item->next() ) ) {
492 w = TQMAX( w, sh.width() );
497 h = TQMAX( h, sh.height() );
506 if ( w == 0 && h == 0 )
507 return TQSize( 100, 200 );
509 return TQSize( 6 + w, h );
516 int w = s.width() + m_listBox->verticalScrollBar()->width();
517 int h = s.height() + m_listBox->horizontalScrollBar()->height();
518 return TQSize( w, h );
523 if ( button != TQt::LeftButton )
544 TQString u = url.url(-1);
550 TQListBoxItem *item = m_listBox->firstItem();
552 if (
static_cast<KURLBarItem*
>( item )->url().url(-1) == u ) {
554 m_listBox->setCurrentItem( item );
555 m_listBox->setSelected( item,
true );
564 m_listBox->clearSelection();
570 TQListBoxItem *item = m_listBox->item( m_listBox->currentItem() );
579 return item ? item->
url() : KURL();
585 TDEConfigGroupSaver cs( appConfig, itemGroup );
586 d->defaultIconSize = m_iconSize;
587 m_iconSize = appConfig->readNumEntry(
"Speedbar IconSize", m_iconSize );
590 TDEConfig *globalConfig = TDEGlobal::config();
591 TDEConfigGroupSaver cs( globalConfig, (TQString)(itemGroup +
" (Global)"));
592 int num = globalConfig->readNumEntry(
"Number of Entries" );
593 for (
int i = 0; i < num; i++ ) {
599 int num = appConfig->readNumEntry(
"Number of Entries" );
600 for (
int i = 0; i < num; i++ ) {
607 TQString number = TQString::number( i );
608 KURL url = KURL::fromPathOrURL( config->readPathEntry( TQString(
"URL_") + number ));
609 if ( !url.isValid() || !KProtocolInfo::isKnownProtocol( url ))
612 TQString description = config->readEntry( TQString(
"Description_") + number );
617 config->readEntry( TQString(
"Icon_") + number ),
618 static_cast<TDEIcon::Group
>(
619 config->readNumEntry( TQString(
"IconGroup_") + number )) );
624 TDEConfigGroupSaver cs1( config, itemGroup );
625 if(!config->hasDefault(
"Speedbar IconSize") && m_iconSize == d->defaultIconSize )
626 config->revertToDefault(
"Speedbar IconSize");
628 config->writeEntry(
"Speedbar IconSize", m_iconSize );
643 writeItem( item, numLocal, config,
false );
651 config->writeEntry(
"Number of Entries", numLocal);
655 bool haveGlobalEntries = (i > numLocal);
657 config->setGroup( itemGroup +
" (Global)" );
660 item =
static_cast<KURLBarItem*
>( m_listBox->firstItem() );
668 writeItem( item, numGlobals, config,
true );
675 config->writeEntry(
"Number of Entries", numGlobals,
true,
true);
687 TQString Description =
"Description_";
688 TQString URL =
"URL_";
689 TQString Icon =
"Icon_";
690 TQString IconGroup =
"IconGroup_";
692 TQString number = TQString::number( i );
693 config->writePathEntry( URL + number, item->
url().prettyURL(),
true, global );
695 config->writeEntry( Description + number, item->
description(),
true,global);
696 config->writeEntry( Icon + number, item->
icon(),
true, global );
697 config->writeEntry( IconGroup + number, item->
iconGroup(),
true, global );
704 if ( KURLDrag::decode( e, urls ) ) {
706 TQString description;
708 bool appLocal =
false;
710 KURL::List::Iterator it = urls.begin();
711 for ( ; it != urls.end(); ++it ) {
712 (void)
insertItem( *it, description, appLocal, icon );
726 static const int IconSize = 10;
727 static const int AddItem = 20;
728 static const int EditItem = 30;
729 static const int RemoveItem = 40;
733 bool smallIcons = m_iconSize < TDEIcon::SizeMedium;
734 TQPopupMenu *popup =
new TQPopupMenu();
735 popup->insertItem( smallIcons ?
736 i18n(
"&Large Icons") : i18n(
"&Small Icons"),
738 popup->insertSeparator();
742 popup->insertItem(SmallIconSet(
"edit"), i18n(
"&Edit Entry..."), EditItem);
743 popup->insertSeparator();
746 popup->insertItem(SmallIconSet(
"document-new"), i18n(
"&Add Entry..."), AddItem);
750 popup->insertItem( SmallIconSet(
"edit-delete"), i18n(
"&Remove Entry"),
754 int result = popup->exec( pos );
757 setIconSize( smallIcons ? TDEIcon::SizeMedium : TDEIcon::SizeSmallMedium );
758 m_listBox->triggerUpdate(
true );
782 i18n(
"Enter a description") );
784 m_listBox->insertItem( item );
797 KURL url = item->
url();
799 TQString icon = item->
icon();
811 m_listBox->triggerUpdate(
true );
825 : TDEListBox( parent, name )
827 m_toolTip =
new KURLBarToolTip(
this );
828 setAcceptDrops(
true );
829 viewport()->setAcceptDrops(
true );
837 void KURLBarListBox::paintEvent( TQPaintEvent* )
840 p.setPen( colorGroup().mid() );
841 p.drawRect( 0, 0, width(), height() );
850 if ( item->isSelected() )
851 urls.append( item->
url() );
855 if ( !urls.isEmpty() )
856 return new KURLDrag( urls,
this,
"urlbar drag" );
861 void KURLBarListBox::contentsDragEnterEvent( TQDragEnterEvent *e )
863 e->accept( KURLDrag::canDecode( e ));
866 void KURLBarListBox::contentsDropEvent( TQDropEvent *e )
871 void KURLBarListBox::contextMenuEvent( TQContextMenuEvent *e )
875 emit contextMenuRequested( itemAt( e->globalPos() ), e->globalPos() );
882 if ( orient == TQt::Vertical ) {
884 setRowMode( Variable );
888 setColumnMode( Variable );
891 m_orientation = orient;
899 TQString& description, TQString& icon,
900 bool& appLocal,
int iconSize,
907 if ( dialog->exec() == TQDialog::Accepted ) {
923 const TQString& description,
924 TQString icon,
bool appLocal,
926 TQWidget *parent,
const char *name )
927 : KDialogBase( parent, name, true,
928 i18n(
"Edit Quick Access Entry"), Ok | Cancel, Ok, true )
930 TQVBox *box =
new TQVBox(
this );
931 TQString text = i18n(
"<qt><b>Please provide a description, URL and icon for this Quick Access entry.</b></br></qt>");
932 TQLabel *label =
new TQLabel( text, box );
933 box->setSpacing( spacingHint() );
935 TQGrid *grid =
new TQGrid( 2, box );
936 grid->setSpacing( spacingHint() );
938 TQString whatsThisText = i18n(
"<qt>This is the text that will appear in the Quick Access panel.<p>"
939 "The description should consist of one or two words "
940 "that will help you remember what this entry refers to.</qt>");
941 label =
new TQLabel( i18n(
"&Description:"), grid );
942 m_edit =
new KLineEdit( grid,
"description edit" );
944 label->setBuddy(
m_edit );
945 TQWhatsThis::add( label, whatsThisText );
946 TQWhatsThis::add(
m_edit, whatsThisText );
948 whatsThisText = i18n(
"<qt>This is the location associated with the entry. Any valid URL may be used. For example:<p>"
949 "%1<br>http://www.trinitydesktop.org<p>"
950 "By clicking on the button next to the text edit box you can browse to an "
951 "appropriate URL.</qt>").arg(TQDir::homeDirPath());
952 label =
new TQLabel( i18n(
"&URL:"), grid );
956 TQWhatsThis::add( label, whatsThisText );
957 TQWhatsThis::add(
m_urlEdit, whatsThisText );
959 whatsThisText = i18n(
"<qt>This is the icon that will appear in the Quick Access panel.<p>"
960 "Click on the button to select a different icon.</qt>");
961 label =
new TQLabel( i18n(
"Choose an &icon:"), grid );
964 if (
icon.isEmpty() )
965 icon = KMimeType::iconForURL(
url );
968 TQWhatsThis::add( label, whatsThisText );
973 if ( TDEGlobal::instance()->aboutData() )
974 appName = TDEGlobal::instance()->aboutData()->programName();
975 if ( appName.isEmpty() )
976 appName = TQString::fromLatin1( TDEGlobal::instance()->instanceName() );
977 m_appLocal =
new TQCheckBox( i18n(
"&Only show when using this application (%1)").arg( appName ), box );
980 i18n(
"<qt>Select this setting if you want this "
981 "entry to show only when using the current application (%1).<p>"
982 "If this setting is not selected, the entry will be available in all "
983 "applications.</qt>")
988 connect(
m_urlEdit->
lineEdit(),TQ_SIGNAL(textChanged (
const TQString & )),
this,TQ_SLOT(urlChanged(
const TQString & )));
990 setMainWidget( box );
997 void KURLBarItemDialog::urlChanged(
const TQString & text )
999 enableButtonOK( !text.isEmpty() );
1006 if ( text.at(0) ==
'/' )
1032 void KURLBarItem::virtual_hook(
int,
void* )
1035 void KURLBar::virtual_hook(
int,
void* )
1038 void KURLBarListBox::virtual_hook(
int id,
void* data )
1039 { TDEListBox::virtual_hook(
id, data ); }
1042 #include "kurlbar.moc"
A dialog that allows editing entries of a KURLBar ( KURLBarItem).
bool applicationLocal() const
~KURLBarItemDialog()
Destroys the dialog.
TDEIconButton * m_iconButton
The TDEIconButton to configure the icon.
static bool getInformation(bool allowGlobal, KURL &url, TQString &description, TQString &icon, bool &appLocal, int iconSize, TQWidget *parent=0)
A convenience method to show the dialog and retrieve all the properties via the given parameters.
KURLBarItemDialog(bool allowGlobal, const KURL &url, const TQString &description, TQString icon, bool appLocal=true, int iconSize=TDEIcon::SizeMedium, TQWidget *parent=0, const char *name=0)
Constructs a KURLBarItemDialog.
KURLRequester * m_urlEdit
The KURLRequester used for editing the url.
TQString description() const
KLineEdit * m_edit
The KLineEdit used for editing the description.
TQCheckBox * m_appLocal
The TQCheckBox to modify the local/global setting.
An item to be used in KURLBar / KURLBarListBox.
void setDescription(const TQString &desc)
Sets the description of this item that will be shown as item-text.
void setIcon(const TQString &icon, TDEIcon::Group group=TDEIcon::Panel)
sets the icon for this item.
TDEIcon::Group iconGroup() const
returns the icon-group of this item (determines icon-effects).
bool applicationLocal() const
returns whether this is a global item or a local one.
virtual const TQPixmap * pixmap() const
returns the pixmap of this item.
TQString toolTip() const
returns the tooltip of this item.
void setToolTip(const TQString &tip)
Sets a tooltip to be used for this item.
virtual int width(const TQListBox *) const
returns the width of this item.
void setApplicationLocal(bool local)
Makes this item a local or global one.
const KURL & url() const
returns the url of this item.
void setURL(const KURL &url)
Sets url for this item.
const TQString & description() const
returns the description of this item.
KURLBarItem(KURLBar *parent, const KURL &url, bool persistent, const TQString &description=TQString::null, const TQString &icon=TQString::null, TDEIcon::Group group=TDEIcon::Panel)
Creates a KURLBarItem to be used in the parent KURLBar.
virtual int height(const TQListBox *) const
returns the height of this item.
TQSize sizeHint() const
returns the preferred size of this item
bool isPersistent() const
returns whether this item is persistent (via KURLBar::writeConfig() and KURLBar::readConfig()) or not...
~KURLBarItem()
Destroys the item.
const TQString & icon() const
returns the icon of this item.
This is the listbox used in KURLBar.
void dropped(TQDropEvent *e)
Emitted when a drop-event happened.
TQt::Orientation orientation() const
virtual TQDragObject * dragObject()
KURLBarListBox(TQWidget *parent=0, const char *name=0)
Constructs a KURLBarListBox.
~KURLBarListBox()
Destroys the box.
virtual void setOrientation(TQt::Orientation orient)
Sets the orientation of the widget.
KURLBar is a widget that displays icons together with a description.
void activated(const KURL &url)
This signal is emitted when the user activated an item, e.g., by clicking on it.
bool m_useGlobal
Whether we support global entries or just local ones.
KURLBarItem * currentItem() const
virtual void clear()
Clears the view, removes all items.
virtual void setListBox(KURLBarListBox *)
Allows to set a custom KURLBarListBox.
virtual bool addNewItem()
Pops up a KURLBarItemDialog to let the user add a new item.
virtual void readConfig(TDEConfig *config, const TQString &itemGroup)
Call this method to read a saved configuration from config, inside the group itemGroup.
virtual void writeItem(KURLBarItem *item, int i, TDEConfig *, bool global)
Called from writeConfig() to save the KURLBarItem item as the i'th entry in the config-object.
virtual void setCurrentItem(const KURL &url)
Makes the item with the url url the current item.
KURLBar(bool useGlobalItems, TQWidget *parent=0, const char *name=0, WFlags f=0)
Constructs a KURLBar.
virtual KURLBarItem * insertDynamicItem(const KURL &url, const TQString &description, const TQString &icon=TQString::null, TDEIcon::Group group=TDEIcon::Panel)
Inserts a new dynamic item into the KURLBar and returns the created KURLBarItem.
virtual void slotContextMenuRequested(TQListBoxItem *, const TQPoint &pos)
Reimplemented to show a contextmenu, allowing the user to add, edit or remove items,...
virtual void setOrientation(TQt::Orientation orient)
The items can be arranged either vertically in one column or horizontally in one row.
virtual void readItem(int i, TDEConfig *config, bool applicationLocal)
Called from readConfig() to read the i'th from config.
virtual bool editItem(KURLBarItem *item)
Pops up a KURLBarItemDialog to let the user edit the properties of item.
virtual void setIconSize(int size)
Sets the default iconsize to be used for items inserted with insertItem.
bool m_isModified
Whether the urlbar was modified by the user (e.g.
virtual void writeConfig(TDEConfig *config, const TQString &itemGroup)
Call this method to save the current configuration into config, inside the group iconGroup.
KURLBarItem * m_activeItem
The currently active item.
~KURLBar()
Destroys the KURLBar.
virtual TQSize sizeHint() const
virtual KURLBarItem * insertItem(const KURL &url, const TQString &description, bool applicationLocal=true, const TQString &icon=TQString::null, TDEIcon::Group group=TDEIcon::Panel)
Inserts a new item into the KURLBar and returns the created KURLBarItem.
Orientation orientation() const
bool m_isImmutable
Whether the urlbar may be modified by the user.
virtual void slotDropped(TQDropEvent *)
Called when a url was dropped onto the bar to show a KURLBarItemDialog.
virtual TQSize minimumSizeHint() const
virtual void slotSelected(TQListBoxItem *)
Called when an item has been selected.
This class is a widget showing a lineedit and a button, which invokes a filedialog.
void setMode(uint m)
Sets the mode of the file dialog.
KLineEdit * lineEdit() const