2 * Copyright 2007 by Christopher Blauvelt <cblauvelt@gmail.com>
3 * Copyright (C) 2007 Matt Broadstone <mbroadst@kde.org>
4 * Copyright (C) 2007 Matias Costa <m.costacano@gmail.com>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU Library General Public License version 2,
8 * or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details
15 * You should have received a copy of the GNU Library General Public
16 * License along with this program; if not, write to the
17 * Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 #ifndef PLASMA_ICONLOADER_H
22 #define PLASMA_ICONLOADER_H
28 #include <QApplication>
29 #include <QDesktopWidget>
33 #include <plasma/applet.h>
38 class IconLoader
: public QObject
43 IconLoader(DefaultDesktop
*parent
);
47 * Get whether device icons will be displayed or not.
48 * @return whether device icons will be displayed
50 bool showDeviceIcons() const;
52 * Sets whether to display device icons or not.
53 * @param show true sets device icons to be displayed.
55 void setShowDeviceIcons(bool show
);
58 * Reloads the configuration for the icon manager
62 bool isGridAligned() const;
63 void setGridAligned(bool align
);
64 QSizeF
gridSize() const;
67 * Places an item on the desktop in the first available space.
69 void alignToGrid(Plasma::Applet
*item
);
70 void alignToGrid(Plasma::Applet
*item
, const QPoint
&pos
, bool moveIntersectingItems
=false);
73 * Get the grid square index where a point in local coordinates is located.
74 * In normal circustances desktop coordinates is screen position.
75 * A grid place is like a square in a checkboard.
78 * @param pos A point in desktop coordinates
79 * @return The grid 2D index pos is located.
81 inline QPoint
mapToGrid(const QPointF
&pos
) const;
84 * A grid place is like a square in a checkboard, and this method returns
85 * its center point. So if you want the top left corner gridSize()/2 must
88 * @param pos A grid place index
89 * @return The center point of the grid square indexed by pos.
91 inline QPointF
mapFromGrid(const QPoint
&pos
) const;
94 * Sets the grid size to the nearest size which results in
95 * a integer number of grid places. If the desktop width is 1024
96 * and the desired grid width is 100 the resulting gridSize will be
97 * 102.4 because it's the nearest width with a integer number of
100 * @arg gridSize The desired grid size to be set.
102 void setGridSize(const QSizeF
& gridSize
);
105 * The width and height of the size returned by this method represents
106 * the grid places a Applet can be placed. A grid place is like a
107 * square in a checkboard, this size represents the white and black squares
110 * @return The grid places for each dimension
112 QSize
gridDimensions() const;
115 * The actions associated with the menu.
116 * @return The menu items relating to icons.
118 virtual QList
<QAction
*> contextActions();
120 bool showIcons() const;
121 void setShowIcons(bool iconsVisible
);
123 //inline const QList<Plasma::Applet*>& desktopItems();
127 void addIcon(const KUrl
&url
);
128 void addIcon(Plasma::Applet
*applet
);
129 void deleteIcon(const KUrl
&url
);
130 void deleteIcon(Plasma::Applet
*applet
);
131 void configureMedia();
135 void setToGrid(Plasma::Applet
* icon
, const QPoint p
);
136 QRectF
nextFreeRect(const QRectF itemRect
);
137 QRectF
nextFreeRect(const QRectF itemRect
, QList
<Plasma::Applet
*> placedItems
);
138 bool intersectsWithItems(const QRectF item
, const QList
<Plasma::Applet
*> &items
) const;
139 QRectF
advanceAlongGrid(QRectF rect
);
140 //bool shiftIcon(Plasma::Applet *icon, Plasma::Applet*);
141 inline QRectF
availableGeometry() const;
143 KDirLister m_desktopDir
;
144 Plasma::DataEngine
*m_solidEngine
;
145 QHash
<QString
, Plasma::Applet
*> m_iconMap
;
146 QHash
<QString
, Plasma::Applet
*> m_solidDevices
;
147 DefaultDesktop
*m_desktop
;
149 QList
<QAction
*> actions
;
151 Qt::Orientation m_orientation
;
159 void newItems(const KFileItemList
& items
);
160 void deleteItem(const KFileItem item
);
161 void appletDeleted(Plasma::Applet
*applet
);
162 void sourceAdded(const QString
&source
);
163 void sourceDeleted(const QString
&source
);
165 void slotAlignHorizontal();
166 void slotAlignVertical();
169 QPoint
IconLoader::mapToGrid(const QPointF
&pos
) const
171 return QPoint(qRound(pos
.x()/m_gridSize
.width()),
172 qRound(pos
.y()/m_gridSize
.height()));
175 QPointF
IconLoader::mapFromGrid(const QPoint
&pos
) const
177 return QPointF(pos
.x()*m_gridSize
.width(),
178 pos
.y()*m_gridSize
.height());
181 QRectF
IconLoader::availableGeometry() const
183 QRectF
desktop(QApplication::desktop()->availableGeometry(0));
184 //take this out once availableGeometry gives us the expected result
185 desktop
.setBottom(desktop
.bottom()-48.0);