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() ),
99 init( icon, group, description, persistent );
104 const TQString&
icon, TDEIcon::Group group )
105 : TQListBoxPixmap( TDEIconLoader::unknown() ),
111 init( icon, group, description,
true );
114 void KURLBarItem::init(
const TQString&
icon, TDEIcon::Group group,
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 );
298 if ( static_cast<const KURLBarListBox *>( lb )->isVertical() )
306 if ( static_cast<const KURLBarListBox *>( lb )->isVertical() )
314 return d->isPersistent;
320 class KURLBar::KURLBarPrivate
325 currentURL.setPath( TQDir::homeDirPath() );
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( TQ_TabFocus );
415 connect( m_listBox, TQT_SIGNAL( mouseButtonClicked(
int, TQListBoxItem *,
const TQPoint & ) ),
417 connect( m_listBox, TQT_SIGNAL( dropped( TQDropEvent * )),
419 connect( m_listBox, TQT_SIGNAL( contextMenuRequested( TQListBoxItem *,
422 connect( m_listBox, TQT_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::Normal, TQColorGroup::Background );
459 TQColor selectedTextColor = pal.color( TQPalette::Normal, TQColorGroup::BrightText );
460 TQColor foreground = pal.color( TQPalette::Normal, TQColorGroup::Foreground );
461 pal.setColor( TQPalette::Normal, TQColorGroup::Base, gray );
462 pal.setColor( TQPalette::Normal, TQColorGroup::HighlightedText, selectedTextColor );
463 pal.setColor( TQPalette::Normal, 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 != Qt::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 );
614 if (description.isEmpty() && url.protocol()==
"beagle") {
616 const KURL kurl(
"beagle:?beagled-status");
617 if (!TDEIO::NetAccess::stat(kurl, uds))
620 description = i18n(
"Desktop Search");
626 config->readEntry( TQString(
"Icon_") + number ),
627 static_cast<TDEIcon::Group
>(
628 config->readNumEntry( TQString(
"IconGroup_") + number )) );
633 TDEConfigGroupSaver cs1( config, itemGroup );
634 if(!config->hasDefault(
"Speedbar IconSize") && m_iconSize == d->defaultIconSize )
635 config->revertToDefault(
"Speedbar IconSize");
637 config->writeEntry(
"Speedbar IconSize", m_iconSize );
652 writeItem( item, numLocal, config,
false );
660 config->writeEntry(
"Number of Entries", numLocal);
664 bool haveGlobalEntries = (i > numLocal);
666 config->setGroup( itemGroup +
" (Global)" );
669 item =
static_cast<KURLBarItem*
>( m_listBox->firstItem() );
677 writeItem( item, numGlobals, config,
true );
684 config->writeEntry(
"Number of Entries", numGlobals,
true,
true);
696 TQString Description =
"Description_";
697 TQString URL =
"URL_";
698 TQString Icon =
"Icon_";
699 TQString IconGroup =
"IconGroup_";
701 TQString number = TQString::number( i );
702 config->writePathEntry( URL + number, item->
url().prettyURL(),
true, global );
704 config->writeEntry( Description + number, item->
description(),
true,global);
705 config->writeEntry( Icon + number, item->
icon(),
true, global );
706 config->writeEntry( IconGroup + number, item->
iconGroup(),
true, global );
713 if ( KURLDrag::decode( e, urls ) ) {
715 TQString description;
717 bool appLocal =
false;
719 KURL::List::Iterator it = urls.begin();
720 for ( ; it != urls.end(); ++it ) {
721 (void)
insertItem( *it, description, appLocal, icon );
735 static const int IconSize = 10;
736 static const int AddItem = 20;
737 static const int EditItem = 30;
738 static const int RemoveItem = 40;
742 bool smallIcons = m_iconSize < TDEIcon::SizeMedium;
743 TQPopupMenu *popup =
new TQPopupMenu();
744 popup->insertItem( smallIcons ?
745 i18n(
"&Large Icons") : i18n(
"&Small Icons"),
747 popup->insertSeparator();
751 popup->insertItem(SmallIconSet(
"edit"), i18n(
"&Edit Entry..."), EditItem);
752 popup->insertSeparator();
755 popup->insertItem(SmallIconSet(
"document-new"), i18n(
"&Add Entry..."), AddItem);
759 popup->insertItem( SmallIconSet(
"edit-delete"), i18n(
"&Remove Entry"),
763 int result = popup->exec( pos );
766 setIconSize( smallIcons ? TDEIcon::SizeMedium : TDEIcon::SizeSmallMedium );
767 m_listBox->triggerUpdate(
true );
773 editItem( static_cast<KURLBarItem *>( item ) );
791 i18n(
"Enter a description") );
793 m_listBox->insertItem( item );
806 KURL url = item->
url();
808 TQString icon = item->
icon();
820 m_listBox->triggerUpdate(
true );
834 : TDEListBox( parent, name )
836 m_toolTip =
new KURLBarToolTip(
this );
837 setAcceptDrops(
true );
838 viewport()->setAcceptDrops(
true );
846 void KURLBarListBox::paintEvent( TQPaintEvent* )
849 p.setPen( colorGroup().mid() );
850 p.drawRect( 0, 0, width(), height() );
859 if ( item->isSelected() )
860 urls.append( item->
url() );
864 if ( !urls.isEmpty() )
865 return new KURLDrag( urls,
this,
"urlbar drag" );
870 void KURLBarListBox::contentsDragEnterEvent( TQDragEnterEvent *e )
872 e->accept( KURLDrag::canDecode( e ));
875 void KURLBarListBox::contentsDropEvent( TQDropEvent *e )
880 void KURLBarListBox::contextMenuEvent( TQContextMenuEvent *e )
884 emit contextMenuRequested( itemAt( e->globalPos() ), e->globalPos() );
891 if ( orient == Qt::Vertical ) {
893 setRowMode( Variable );
897 setColumnMode( Variable );
900 m_orientation = orient;
908 TQString& description, TQString& icon,
909 bool& appLocal,
int iconSize,
916 if ( dialog->exec() == TQDialog::Accepted ) {
920 icon = dialog->
icon();
932 const TQString& description,
933 TQString icon,
bool appLocal,
935 TQWidget *parent,
const char *name )
936 : KDialogBase( parent, name, true,
937 i18n(
"Edit Quick Access Entry"), Ok | Cancel, Ok, true )
939 TQVBox *box =
new TQVBox(
this );
940 TQString text = i18n(
"<qt><b>Please provide a description, URL and icon for this Quick Access entry.</b></br></qt>");
941 TQLabel *label =
new TQLabel( text, box );
942 box->setSpacing( spacingHint() );
944 TQGrid *grid =
new TQGrid( 2, box );
945 grid->setSpacing( spacingHint() );
947 TQString whatsThisText = i18n(
"<qt>This is the text that will appear in the Quick Access panel.<p>" 948 "The description should consist of one or two words " 949 "that will help you remember what this entry refers to.</qt>");
950 label =
new TQLabel( i18n(
"&Description:"), grid );
951 m_edit =
new KLineEdit( grid,
"description edit" );
953 label->setBuddy(
m_edit );
954 TQWhatsThis::add( label, whatsThisText );
955 TQWhatsThis::add(
m_edit, whatsThisText );
957 whatsThisText = i18n(
"<qt>This is the location associated with the entry. Any valid URL may be used. For example:<p>" 958 "%1<br>http://www.trinitydesktop.org<p>" 959 "By clicking on the button next to the text edit box you can browse to an " 960 "appropriate URL.</qt>").arg(TQDir::homeDirPath());
961 label =
new TQLabel( i18n(
"&URL:"), grid );
965 TQWhatsThis::add( label, whatsThisText );
966 TQWhatsThis::add(
m_urlEdit, whatsThisText );
968 whatsThisText = i18n(
"<qt>This is the icon that will appear in the Quick Access panel.<p>" 969 "Click on the button to select a different icon.</qt>");
970 label =
new TQLabel( i18n(
"Choose an &icon:"), grid );
973 if ( icon.isEmpty() )
974 icon = KMimeType::iconForURL( url );
977 TQWhatsThis::add( label, whatsThisText );
982 if ( TDEGlobal::instance()->aboutData() )
983 appName = TDEGlobal::instance()->aboutData()->programName();
984 if ( appName.isEmpty() )
985 appName = TQString::fromLatin1( TDEGlobal::instance()->instanceName() );
986 m_appLocal =
new TQCheckBox( i18n(
"&Only show when using this application (%1)").arg( appName ), box );
989 i18n(
"<qt>Select this setting if you want this " 990 "entry to show only when using the current application (%1).<p>" 991 "If this setting is not selected, the entry will be available in all " 992 "applications.</qt>")
997 connect(
m_urlEdit->
lineEdit(),TQT_SIGNAL(textChanged (
const TQString & )),
this,TQT_SLOT(urlChanged(
const TQString & )));
999 setMainWidget( box );
1006 void KURLBarItemDialog::urlChanged(
const TQString & text )
1008 enableButtonOK( !text.isEmpty() );
1015 if ( text.at(0) ==
'/' )
1041 void KURLBarItem::virtual_hook(
int,
void* )
1044 void KURLBar::virtual_hook(
int,
void* )
1047 void KURLBarListBox::virtual_hook(
int id,
void* data )
1048 { TDEListBox::virtual_hook(
id, data ); }
1051 #include "kurlbar.moc"
void dropped(TQDropEvent *e)
Emitted when a drop-event happened.
virtual void writeConfig(TDEConfig *config, const TQString &itemGroup)
Call this method to save the current configuration into config, inside the group iconGroup.
const TQString & icon() const
returns the icon of this item.
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...
TQSize sizeHint() const
returns the preferred size of this item
~KURLBarListBox()
Destroys the box.
bool isPersistent() const
returns whether this item is persistent (via KURLBar::writeConfig() and KURLBar::readConfig()) or not...
virtual void clear()
Clears the view, removes all items.
TDEIcon::Group iconGroup() const
returns the icon-group of this item (determines icon-effects).
~KURLBarItemDialog()
Destroys the dialog.
void activated(const KURL &url)
This signal is emitted when the user activated an item, e.g., by clicking on it.
virtual void setIconSize(int size)
Sets the default iconsize to be used for items inserted with insertItem.
virtual void slotDropped(TQDropEvent *)
Called when a url was dropped onto the bar to show a KURLBarItemDialog.
~KURLBarItem()
Destroys the item.
void setToolTip(const TQString &tip)
Sets a tooltip to be used for this item.
virtual void slotSelected(TQListBoxItem *)
Called when an item has been selected.
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.
Orientation orientation() const
void setDescription(const TQString &desc)
Sets the description of this item that will be shown as item-text.
virtual void setListBox(KURLBarListBox *)
Allows to set a custom KURLBarListBox.
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 bool editItem(KURLBarItem *item)
Pops up a KURLBarItemDialog to let the user edit the properties of item.
KURLBarItem * currentItem() const
KLineEdit * lineEdit() const
const KURL & url() const
returns the url of this item.
Qt::Orientation orientation() const
virtual void setOrientation(Qt::Orientation orient)
Sets the orientation of the widget.
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.
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.
void setMode(uint m)
Sets the mode of the file dialog.
virtual TQDragObject * dragObject()
KURLBar is a widget that displays icons together with a description.
TDEIconButton * m_iconButton
The TDEIconButton to configure the icon.
TQCheckBox * m_appLocal
The TQCheckBox to modify the local/global setting.
virtual TQSize minimumSizeHint() const
TQString description() const
void setIcon(const TQString &icon, TDEIcon::Group group=TDEIcon::Panel)
sets the icon for this item.
virtual void readConfig(TDEConfig *config, const TQString &itemGroup)
Call this method to read a saved configuration from config, inside the group itemGroup.
bool m_isImmutable
Whether the urlbar may be modified by the user.
virtual void readItem(int i, TDEConfig *config, bool applicationLocal)
Called from readConfig() to read the i'th from config.
KLineEdit * m_edit
The KLineEdit used for editing the description.
bool m_isModified
Whether the urlbar was modified by the user (e.g.
virtual const TQPixmap * pixmap() const
returns the pixmap of this item.
This class is a widget showing a lineedit and a button, which invokes a filedialog.
bool applicationLocal() const
returns whether this is a global item or a local one.
bool m_useGlobal
Whether we support global entries or just local ones.
virtual int width(const TQListBox *) const
returns the width of this item.
An item to be used in KURLBar / KURLBarListBox.
KURLBar(bool useGlobalItems, TQWidget *parent=0, const char *name=0, WFlags f=0)
Constructs a KURLBar.
bool applicationLocal() const
virtual void setCurrentItem(const KURL &url)
Makes the item with the url url the current item.
KURLRequester * m_urlEdit
The KURLRequester used for editing the url.
~KURLBar()
Destroys the KURLBar.
TQString toolTip() const
returns the tooltip of this item.
A dialog that allows editing entries of a KURLBar ( KURLBarItem).
virtual void slotContextMenuRequested(TQListBoxItem *, const TQPoint &pos)
Reimplemented to show a contextmenu, allowing the user to add, edit or remove items, or change the iconsize.
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.
KURLBarListBox(TQWidget *parent=0, const char *name=0)
Constructs a KURLBarListBox.
KURLBarItem * m_activeItem
The currently active item.
virtual bool addNewItem()
Pops up a KURLBarItemDialog to let the user add a new item.
virtual TQSize sizeHint() const
const TQString & description() const
returns the description of this item.
void setApplicationLocal(bool local)
Makes this item a local or global one.
This is the listbox used in KURLBar.
virtual int height(const TQListBox *) const
returns the height of this item.
void setURL(const KURL &url)
Sets url for this item.
virtual void setOrientation(Qt::Orientation orient)
The items can be arranged either vertically in one column or horizontally in one row.