summaryrefslogtreecommitdiffstats
path: root/kpovmodeler/pmlibraryiconview.h
blob: a30ef529b433c164f040900f7f412c78c4377627 (plain)
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
//-*-C++-*-
/*
**************************************************************************
                                 description
                             --------------------
    copyright            : (C) 2003 by Luis Carvalho
    email                : [email protected]
**************************************************************************

**************************************************************************
*                                                                        *
*  This program 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.                                   *
*                                                                        *
**************************************************************************/

#ifndef PMLIBRARYICONVIEW_H
#define PMLIBRARYICONVIEW_H

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <kiconview.h>

class PMLibraryHandle;

/**
 * This class is the drag and drop object for the icon view
 */
class PMLibraryIconDrag : public QIconDrag
{
   Q_OBJECT
public:
   /** Constructor */
   PMLibraryIconDrag( QWidget * dragSource, const char* name = 0 ) : QIconDrag( dragSource, name ) {}

   /** @return The ith format, or NULL. */
   const char* format( int i ) const;
   /** @return The encoded payload of this object, in the specified MIME format. */
   QByteArray encodedData( const char* mime ) const;
   /** @return True if the information in e can be decoded */
   static bool canDecode( QMimeSource* e );
   /**
    * Attempts to decode the data in e
    * @return True if successful otherwise returns false
    */
   static bool decode( QMimeSource* e, QStringList& StrList, QValueList<bool>& subLibList );
   /** Adds a item to the object */
   void append( const QIconDragItem &item, const QRect &pr, const QRect &tr, const QString &path, bool subLib );

private:
   QStringList m_paths;
   QValueList<bool> m_subLibs;
};

/**
 * This class provides a view to browse objects, showing their previews.
 */
class PMLibraryIconView: public KIconView
{
   Q_OBJECT
public:
   PMLibraryIconView( QWidget *parent, const char* name = NULL );

   /**
    * Set the library base path
    */
   void setLibrary( PMLibraryHandle* h );
   /**
    * Returns the library in view
    */
   PMLibraryHandle* library( ) const { return m_pLibrary; }

public slots:
   /**
    * refresh the icon view
    */
   void refresh( );

   /** called when an Item is dropped onto the view */
   void slotDropped( QDropEvent *e, const QValueList<QIconDragItem>& );

protected:
   /** @return a QDragObject for drag and drop */
   virtual QDragObject* dragObject( );

private:
   PMLibraryHandle *m_pLibrary;
   PMLibraryHandle *m_pCurrentLibrary;
};

/**
 * This class holds a library object's icon. It also remembers the path
 * where the file is.
 */
class PMLibraryIconViewItem: public KIconViewItem
{
public:
   PMLibraryIconViewItem( QIconView *parent, const QString& text, const QString& path, bool isSubLibrary );
   PMLibraryIconViewItem( QIconView *parent, const QString& text, const QImage& image, const QString& path, bool isSubLibrary );

   /** Get the path of the entry */
   QString path( ) const { return m_path; }
   /** Is the entry a sublib library? */
   bool isSubLibrary( ) const { return m_isSubLibrary; }
   /** Reimplement accept drop to take items */
   virtual bool acceptDrop( const QMimeSource *mime ) const;

protected:
   /** Tokes a dropped item */
   void dropped( QDropEvent *evt, const QValueList<QIconDragItem>& );
   /** Checks for the existance of oldpath and generates a new path as required */
   QString newPath( const QString oldPath, bool subLib );

private:
   QString m_path;
   bool    m_isSubLibrary;
};

#endif