KRename – powerful batch renamer
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

kmylistbox.h 5.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. /***************************************************************************
  2. kmylistbox.h - description
  3. -------------------
  4. begin : Tue Oct 16 2001
  5. copyright : (C) 2001 by Dominik Seichter
  6. email : domseichter@web.de
  7. ***************************************************************************/
  8. /***************************************************************************
  9. * *
  10. * This program is free software; you can redistribute it and/or modify *
  11. * it under the terms of the GNU General Public License as published by *
  12. * the Free Software Foundation; either version 2 of the License, or *
  13. * (at your option) any later version. *
  14. * *
  15. ***************************************************************************/
  16. #ifndef KMYLISTBOX_H
  17. #define KMYLISTBOX_H
  18. // KDE includes
  19. #include <tdelistbox.h>
  20. #include <kurl.h>
  21. #include <tdefileitem.h>
  22. // TQt includes
  23. #include <tqmutex.h>
  24. #include <tqstringlist.h>
  25. class ThreadedLister;
  26. class KFileItem;
  27. class KURLLabel;
  28. class TQDragObject;
  29. class TQPixmap;
  30. class TQPainter;
  31. class TQPoint;
  32. class KMyListBox : public TDEListBox {
  33. Q_OBJECT
  34. public:
  35. enum { ASCENDING = 1, DESCENDING = 2, RANDOM = 3, NUMMERIC = 4, UNSORTED = 0 };
  36. KMyListBox(TQWidget* parent=0, const char* name=0, WFlags fl=0);
  37. ~KMyListBox();
  38. void removeItem( int index );
  39. void addDir( const KURL & dirname, const TQString & m_filter, bool m_hidden, bool recursively, bool dirnames = false );
  40. void addDirName( const KURL & dirname, const TQString & m_filter, bool m_hidden, bool recursive = false );
  41. void setPreview( bool prv );
  42. inline int sorting() const { return m_sorting; }
  43. void setName( bool name );
  44. void move( int i );
  45. void setPreviewSize( int size );
  46. inline int getPreviewSize() const { return previewSize; }
  47. KURL url( int index ) const;
  48. bool dir( int index ) const;
  49. bool isFile( const KURL & f, bool autoadd = true );
  50. void positionLabel();
  51. void clear();
  52. /**
  53. * returns the number of currently running ThreadedListers for adding files
  54. * or 0 if there is no file adding in progress right now.
  55. */
  56. unsigned int runningAddListeners();
  57. public slots:
  58. void moveMode();
  59. void moveDown();
  60. void moveDown( int i );
  61. void moveUp();
  62. void moveUp( int i );
  63. void setSorting( int s );
  64. void addFile( const KURL & filename, bool isfile = false );
  65. void addDirName( const KURL & dirname );
  66. signals:
  67. // emited when new item is drag'n'dropped into listobox
  68. // or when files are removed or something similar
  69. void updateCount();
  70. void updatePreview();
  71. void deletePressed();
  72. void addFiles();
  73. void currentlyAddingFiles();
  74. private:
  75. void preview( KURL::List list );
  76. void dropEvent( TQDropEvent* e );
  77. void dragEnterEvent( TQDragEnterEvent* e );
  78. void viewportMousePressEvent( TQMouseEvent* e );
  79. void viewportMouseReleaseEvent( TQMouseEvent* e );
  80. void viewportMouseMoveEvent( TQMouseEvent* e );
  81. void keyPressEvent( TQKeyEvent* e );
  82. void keyReleaseEvent( TQKeyEvent* e );
  83. bool isInList( KURL text );
  84. void sortAscending();
  85. void sortDescending();
  86. void sortUnsorted();
  87. void sortRandom();
  88. void sortNummeric();
  89. void sortList();
  90. void setButtonText();
  91. int compareNummeric( const TQString & s1, const TQString & s2 );
  92. const TQString findNumInString( unsigned int pos, const TQString & s );
  93. private slots:
  94. void openFile( TQListBoxItem* item );
  95. void select( TQListBoxItem* item );
  96. void previewDone( const KFileItem* item, const TQPixmap &pixmap );
  97. void previewFailed( const KFileItem* item );
  98. void previewFinished();
  99. void listerDone( ThreadedLister* lister );
  100. protected:
  101. void resizeEvent( TQResizeEvent* e );
  102. void customEvent( TQCustomEvent* e );
  103. void paintEvent( TQPaintEvent* e );
  104. bool drag;
  105. bool mousePressed;
  106. bool ctrlPressed;
  107. bool shiftPressed;
  108. bool moving;
  109. int previewSize;
  110. int m_sorting;
  111. unsigned int m_running_lister_counter;
  112. TQMutex m_add_mutex;
  113. KURLLabel* label;
  114. TQDragObject* drobj;
  115. TQPoint presspos;
  116. };
  117. class KMyListBoxItem : public TQListBoxItem {
  118. public:
  119. KMyListBoxItem( const KMyListBoxItem* item );
  120. KMyListBoxItem( const KURL&, bool );
  121. bool hasPreview() const { return m_has_preview; }
  122. static void setName( bool b );
  123. static void setPreview( bool b );
  124. void setPixmap( const TQPixmap & pix );
  125. static bool preview() { return m_preview; }
  126. static bool name() { return m_name; }
  127. inline bool dir() const { return m_dir; }
  128. inline KURL url() const { return m_url; }
  129. inline const TQPixmap* pixmap() const { return &pm; }
  130. private:
  131. TQString text() const;
  132. protected:
  133. virtual void paint( TQPainter *painter );
  134. virtual int width( const TQListBox* ) const;
  135. virtual int height( const TQListBox* lb ) const;
  136. private:
  137. KURL m_url;
  138. bool m_dir;
  139. bool m_has_preview;
  140. TQPixmap pm;
  141. static bool m_preview;
  142. static bool m_name;
  143. };
  144. #endif