1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284
|
#ifndef PlacesWidget_h
#define PlacesWidget_h
/******************************************************************************
*
* Copyright (C) 2002 Hugo PEREIRA <mailto: hugo.pereira@free.fr>
*
* This is free software; you can redistribute it and/or modify it under the
* terms of the GNU General Public License as published by the Free Software
* Foundation; either version 2 of the License, or (at your option) any later
* version.
*
* This software is distributed in the hope that it will be useful, but WITHOUT
* Any WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*
*******************************************************************************/
#include "Counter.h"
#include "BaseFileInfo.h"
#include "IconSize.h"
#include "FileSystemWatcher.h"
#include <QList>
#include <QMimeData>
#include <QAbstractButton>
#include <QAbstractItemView>
#include <QAction>
#include <QButtonGroup>
#include <QDragEnterEvent>
#include <QDragMoveEvent>
#include <QDragLeaveEvent>
#include <QLayout>
#include <QPaintEvent>
#include <QWidget>
// forward declaration
namespace Private
{
class PlacesToolTipWidget;
class PlacesWidgetItem;
}
class BaseFileIconProvider;
class IconSizeMenu;
//* places widget
class PlacesWidget: public QWidget, private Base::Counter<PlacesWidget>
{
Q_OBJECT
public:
//* constructor
explicit PlacesWidget( QWidget* = nullptr );
//* set icon provider
void setIconProvider( BaseFileIconProvider* );
//* true if empty
bool isEmpty() const
{ return group_->buttons().isEmpty(); }
//* list of items
QList<BaseFileInfo> items() const;
//* set item enabled
bool setItemIsValid( const BaseFileInfo&, bool );
//* event filter
bool eventFilter( QObject*, QEvent* ) override;
Q_SIGNALS:
//* item added
void remoteItemAdded( const BaseFileInfo& );
//* item selected
void itemSelected( const BaseFileInfo& );
public Q_SLOTS:
//* clear all items
void clear();
//* add item
void add( const BaseFileInfo& );
//* add item
void add( const QString&, const BaseFileInfo& );
//* add item
void add( const QIcon&, const QString&, const BaseFileInfo& );
//* insert item
void insert( int, const BaseFileInfo& );
//* insert item
void insert( int, const QString&, const BaseFileInfo& );
//* insert item
void insert( int, const QIcon&, const QString&, const BaseFileInfo& );
protected Q_SLOTS:
//* button clicked
void _buttonClicked( QAbstractButton* );
//* update focus
void _updateFocus( QAbstractButton* );
//* update context menu
void _updateContextMenu( const QPoint& );
//* icon size
void _updateIconSize( IconSize::Size );
//* add item
void _addItem();
//* add separator
void _addSeparator();
//* add separator
void _insertSeparator();
//* edit item
void _editItem();
//* remove item
void _removeItem();
//* update item state
void _updateItems();
//* hide item
void _toggleHideItem( bool );
//* show all entries
void _toggleShowAllEntries( bool );
protected:
//*@name event handlers
//@{
//* drag enter event
void dragEnterEvent( QDragEnterEvent* ) override;
//* drag move
void dragMoveEvent( QDragMoveEvent* ) override;
//* drag leave
void dragLeaveEvent( QDragLeaveEvent* ) override;
//* drop
void dropEvent( QDropEvent* ) override;
//* mouse press
void mousePressEvent( QMouseEvent* ) override;
//* paint event
void paintEvent( QPaintEvent* ) override;
//@}
//* Read fileList from file
bool _read();
//* write fileList to file
bool _write();
//* install default folders
void _addDefaultPlaces();
//* set db file
bool _setDBFile( const File& );
//* update drag state
void _updateDragState() const;
//* drag target
QPoint _updateDragTarget( const QPoint& ) const;
//* return item index based on position
int _index( const QPoint& ) const;
//* true if mime data can be decoded
bool _canDecode( const QMimeData* ) const;
//* decode mime data
QList<BaseFileInfo> _decode( const QMimeData* ) const;
//* return item that have focus or none
Private::PlacesWidgetItem* _focusItem() const;
private Q_SLOTS:
//* update configuration
void _updateConfiguration();
//* save configuration
void _saveConfiguration();
private:
//* install actions
void _installActions();
//* dummy treeview, needed for rendering items
QAbstractItemView* itemView_ = nullptr;
//* button layout
QBoxLayout* buttonLayout_ = nullptr;
//* button group
QButtonGroup* group_ = nullptr;
//* icon size menu
IconSizeMenu* iconSizeMenu_ = nullptr;
//* tooltip widget
Private::PlacesToolTipWidget* toolTipWidget_ = nullptr;
//* list of items
QList<Private::PlacesWidgetItem*> items_;
//* focus item (for context menu actions)
Private::PlacesWidgetItem* focusItem_ = nullptr;
//* drag item
Private::PlacesWidgetItem* dragItem_ = nullptr;
//* icon provider
BaseFileIconProvider* iconProvider_ = nullptr;
//* file system watcher, for local selection frame
FileSystemWatcher fileSystemWatcher_;
//* file from/to wich the files are saved
File dbFile_;
//* true if drag is in progress
bool dragInProgress_ = false;
//* drag point (for internal dragging)
QPoint dragPoint_;
//* drag point
QPoint dragTarget_;
//*@name actions
//@{
//* add item
QAction* addItemAction_ = nullptr;
//* add separator
QAction* addSeparatorAction_ = nullptr;
//* edit item
QAction* editItemAction_ = nullptr;
//* delete item
QAction* removeItemAction_ = nullptr;
//* hide item
QAction* hideItemAction_ = nullptr;
//* show all entries action
QAction* showAllEntriesAction_ = nullptr;
//@}
};
#endif
|