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
|
/*
* This file is part of Magellan <http://www.kAlliance.org/Magellan>
*
* Copyright (c) 1998-2000 Teodor Mihai <teddy@ireland.com>
* Copyright (c) 1998-2000 Laur Ivan <laur.ivan@ul.ie>
* Copyright (c) 1999-2000 Virgil Palanciuc <vv@ulise.cs.pub.ro>
*
* Requires the Qt widget libraries, available at no cost at
* http://www.troll.no/
*
* Also requires the KDE libraries, available at no cost at
* http://www.kde.org/
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/
/*
This file includes the definition of the so-called Tile Classes.
There are two kinds of objects defined here: TileWidget and SortingWidget.
A SortingWidget is a GUI object which contains and manages a collection of TileWidgets.
It can automatically arrange, sort, create, drag, copy, paste, display right-click menus etc. on its children.
They are pure classes, and they must be inherited to become useful.
*/
#ifndef __SortingWidget__
#define __SortingWidget__
#include <stdio.h>
#include <qwidget.h>
#include <qstring.h>
#include <qlist.h>
#include <qpopupmenu.h>
#include <qevent.h>
#include <qscrollview.h>
#include <datahandlerimpl.h>
#include <tilewidget.h>
class SortingWidget : public QScrollView, public DataHandlerImpl
{
Q_OBJECT
public:
// Creates a SortingWidget object.
SortingWidget(QWidget *parent=0, const char *name=0, WFlags f=0);
// Destroys a SortingWidget object.
~SortingWidget();
// reimplemented from DataHandler
virtual void registerWidget(DataWidget *);
virtual void unregisterWidget(DataWidget *);
// Adds a TileWidget child. The child will be shown immediately in the correct position according to its size or sorting keys.
// Queries the TileWidget for sorting information on the first insertion and builds the sortPopup.
virtual void addChild(QWidget *child);
// Removed a child from the SortingWidget without deleting it. The SortingWidget is updated if "update" is true.
// Normally, the "update" parameter is used only when more than one children are removed at once, to avoid multiple updates.
virtual void removeChild(QWidget *child);
// Removes all child widgets
virtual void clear();
// Enables or disables the fixed height children property. If true, horizontal arranging chains are used, otherwise vertical.
// This should be called only once, in the constructor.
virtual void setChildFixedHeight(bool fixed_height=true);
// Returns the fixedHeight property value.
virtual bool childFixedHeight();
// Enables or disabled the width resize feature of the SortingWidget. Should be called only once, in the constructor.
virtual void enableWidthResize(bool wres=true);
// Returns the width resize property value.
virtual bool widthResizeEnabled();
// returns true if it can draw the vertical lines
bool canDrawLines();
// set if it can display the vertical "columns separators"
void setCanDrawLines(bool);
// Sets the children width.
virtual void setChildWidth(int width);
// Sets the children height. Has no effect unless the children have fixed height, as declared by setChildrenFixedHeight().
virtual void setChildHeight(int height);
// Sets the children type (see mailer.h for a list of types).
virtual void setChildType(int type);
// Returns the children type.
virtual int getChildType();
// Sets the children mimetype. The SortingWidget will accept only drops which can be converted to this mimetype.
virtual void setChildMimeType(const char *m="application/octet-stream");
// Returns the children mimetype.
virtual const char *getChildMimeType();
// Returns the child found at point viewport coordinated, or NULL if no child can be found there.
virtual TileWidget* childAt( QPoint );
// Returns the children dimensions. If the children don't have fixed height the "h" value should be ignored.
virtual void getChildDimensions(int &w, int &h);
// Returns the (x, y) coordinates of the n-th child, specified in "index".
virtual void getIndexPosition(int index, int &x, int &y);
// Sets the horizontal spacing.
virtual void setXSpacing(int xsp);
// Sets the vertical spacing.
virtual void setYSpacing(int ysp);
// Allows the SortingWidget to display the main popup when a child is right-clicked when childPopup doesn't exist.
virtual void setAllwaysShowPopup(bool t=true);
// Returns the allwaysPopup property.
virtual bool allwaysShowPopup();
// Enables multiple selection.
virtual void setMultipleSelect(bool t=true);
// Returns true if multiple selection is enabled.
virtual bool multipleSelect();
// Enables the sort popup, if the parameter is true.
virtual void setShowSorting(bool t=true);
// Returns true is the sort popup is enabled.
virtual bool showSorting();
// Makes the global popup.
virtual void makeGlobalPopup();
// Makes the child popup.
virtual void makeChildPopup();
// Shows the global popup.
virtual void popupGlobal();
// Shows the child popup (or the global, the child popup is null, the main popup exists and allwaysPopup is true).
virtual void popupChild();
// selection list
QList<TileWidget> selected();
// children list
QList<TileWidget> children();
public slots:
// Sorts the children using the n-th key.
virtual void sort(int number);
virtual bool eventFilter(QObject *o, QEvent *e);
virtual void triggerUpdate();
public slots:
void setStartView(const QString&);
void setStartView(TileWidget *);
// screen update
virtual void screenUpdate();
protected:
// private data
int childW, childH;
int xSpacing, ySpacing;
int currentKey;
int childType;
QPopupMenu *mainPopup, *sortPopup, *childPopup;
void querySorting();
QString childMimeType;
bool fixedHeight, wResize, allwaysPopup, allowMultiple, enableDrags, showSort;
bool canDoResizeHere;
bool isDoResize;
// internal event handlers
virtual void resizeEvent(QResizeEvent *e); // handles resize events
// internal methods
virtual int makePosChain(); // computes widget positions and move widget at this position, returning the new viewport width or height, according to the current sort chain
void handleMouseDoubleClickEvent( TileWidget *, QMouseEvent *e );
void handleMousePressEvent( TileWidget *, QMouseEvent *e );
void handleMouseReleaseEvent( TileWidget *, QMouseEvent *e );
void handleMouseMoveEvent( TileWidget *, QMouseEvent *e );
void beginUnclippedPainter();
void endUnclippedPainter();
void endRectDraw();
void startRectDraw();
void continueRectDraw( int );
void drawLines();
void eraseLines();
void blackLines();
QPainter* unclippedPainter;
int currentColumn;
int currentColumnWidth;
int oldColumnWidth;
bool _canDrawLines;
bool m_isDragging;
};
#endif
|