10
10
#include "filelistitem.h"
11
12
#include "taggedfile.h"
13
16
#include <qapplication.h>
14
17
#include <qpainter.h>
15
18
#include <qpixmap.h>
19
#include <qfileinfo.h>
17
21
/** Empty pixmap, will be allocated in constructor */
18
QPixmap *FileListItem::nullPixmap = 0;
22
QPixmap* FileListItem::nullPixmap = 0;
19
23
/** Pixmap for modified file, will be allocated in constructor */
20
QPixmap *FileListItem::modifiedPixmap = 0;
24
QPixmap* FileListItem::modifiedPixmap = 0;
21
25
/** Pixmap for V1V2, will be allocated in constructor */
22
QPixmap *FileListItem::v1v2Pixmap = 0;
26
QPixmap* FileListItem::v1v2Pixmap = 0;
23
27
/** Pixmap for V1, will be allocated in constructor */
24
QPixmap *FileListItem::v1Pixmap = 0;
28
QPixmap* FileListItem::v1Pixmap = 0;
25
29
/** Pixmap for V2, will be allocated in constructor */
26
QPixmap *FileListItem::v2Pixmap = 0;
30
QPixmap* FileListItem::v2Pixmap = 0;
27
31
/** Pixmap for "no tag", will be allocated in constructor */
28
QPixmap *FileListItem::notagPixmap = 0;
32
QPixmap* FileListItem::notagPixmap = 0;
33
/** Pixmap for closed folder, will be allocated in constructor */
34
QPixmap* FileListItem::folderClosedPixmap = 0;
35
/** Pixmap for open folder, will be allocated in constructor */
36
QPixmap* FileListItem::folderOpenPixmap = 0;
30
38
/* The bitmaps are stored here instead of using KDE bitmaps to make
31
39
it work for the Qt only versions. */
32
40
/** picture for modified pixmap */
33
static const char * const modified_xpm[] = {
41
static const char* const modified_xpm[] = {
106
114
"#.#.#.#.#.#.#.#."
110
static const char * const v1v2_xpm[] = {
133
static const char * const v1_xpm[] = {
156
static const char * const v2_xpm[] = {
179
static const char * const notag_xpm[] = {
117
/** picture with V1 and V2 */
118
static const char* const v1v2_xpm[] = {
140
/** picture with V1 */
141
static const char* const v1_xpm[] = {
163
/** picture with V2 */
164
static const char* const v2_xpm[] = {
186
/** picture with NO TAG */
187
static const char* const notag_xpm[] = {
201
/** width of both pixmaps, got using QPixmap::width() */
202
static const int pixmapWidth = 16;
203
/** height of both pixmaps, got using QPixmap::height() */
204
static const int pixmapHeight = 16;
209
/** picture with closed folder */
210
static const char* folder_closed_xpm[]={
239
/** picture with open folder */
240
static const char* folder_open_xpm[]={
209
* @param file tagged file (will be owned by this item)
211
FileListItem::FileListItem(TaggedFile* file) : m_file(file)
272
* @param parent parent file list
273
* @param after this item is inserted after item @a after
274
* @param file tagged file (will be owned by this item)
276
FileListItem::FileListItem(FileList* parent, FileListItem* after,
278
Q3ListViewItem(parent, after), m_file(file), m_dirInfo(0)
284
* Constructor for non top-level items.
286
* @param parent parent file list item
287
* @param after this item is inserted after item @a after
288
* @param file tagged file (will be owned by this item)
290
FileListItem::FileListItem(FileListItem* parent, FileListItem* after,
292
Q3ListViewItem(parent, after), m_file(file), m_dirInfo(0)
298
* Initialize file list item.
299
* Common initialization for all constructors.
301
void FileListItem::init()
213
303
setInSelection(false);
215
setText(m_file->getFilename());
305
setText(0, m_file->getFilename());
218
308
// this two objects should be destructed when the program terminates.
244
342
FileListItem::~FileListItem()
349
* Paints the contents of one column of an item.
352
* @param cg color group
353
* @param column number of column
355
* @param align alignment
357
void FileListItem::paintCell(QPainter* p, const QColorGroup& cg,
358
int column, int width, int align)
360
if (Kid3App::s_miscCfg.m_markTruncations &&
361
column == 0 && m_file && m_file->getTruncationFlags() != 0) {
363
#if QT_VERSION >= 0x040000
364
g.setColor(QPalette::Window, Qt::red);
366
g.setColor(QColorGroup::Base, Qt::red);
368
Q3ListViewItem::paintCell(p, g, column, width, align);
370
Q3ListViewItem::paintCell(p, cg, column, width, align);
375
* Opens or closes an item.
377
* @param o true to open
379
void FileListItem::setOpen(bool o)
382
setPixmap(0, o ? *folderOpenPixmap : *folderClosedPixmap);
384
if (o && !childCount()) {
385
listView()->setUpdatesEnabled(false);
386
FileList::readSubDirectory(m_dirInfo, this, 0);
387
listView()->setUpdatesEnabled(true);
391
QListViewItem::setOpen(o);
395
* Called before showing the item.
397
void FileListItem::setup()
402
QListViewItem::setup();
262
setText(m_file->getFilename());
267
* Get height of item.
269
* @param lb listbox containing the item
273
int FileListItem::height(const Q3ListBox* lb) const
275
int h = text().isEmpty() ? pixmapHeight :
276
QMAX(pixmapHeight, lb->fontMetrics().lineSpacing() + 1);
277
return QMAX(h, QApplication::globalStrut().height());
283
* @param lb listbox containing the item
287
int FileListItem::width(const Q3ListBox* lb) const
289
if (text().isEmpty()) {
290
return QMAX(pixmapWidth * 2 + 6, QApplication::globalStrut().width());
292
return QMAX(pixmapWidth * 2 + 6 + lb->fontMetrics().width(text()), QApplication::globalStrut().width());
298
* @param painter painter used
300
void FileListItem::paint(QPainter *painter)
302
static const QPixmap *tagpm[] = {
303
notagPixmap, v1Pixmap, v2Pixmap, v1v2Pixmap, nullPixmap
306
if (!m_file->isTagInformationRead()) {
310
if (m_file->hasTagV1()) {
313
if (m_file->hasTagV2()) {
317
painter->drawPixmap(3, 0, m_file->isChanged() ? *modifiedPixmap : *nullPixmap);
318
painter->drawPixmap(pixmapWidth + 3, 0, *tagpm[tagpmIdx]);
319
if (!text().isEmpty()) {
320
QFontMetrics fm = painter->fontMetrics();
321
painter->drawText(pixmapWidth * 2 + 5,
322
pixmapHeight < fm.height() ?
323
fm.ascent() + fm.leading() / 2 :
324
pixmapHeight / 2 - fm.height() / 2 + fm.ascent(),
418
setText(0, m_file->getFilename());
424
* Set directory information.
425
* An item can represent a file (file is set) or
426
* a directory (directory information is set).
427
* The item takes ownership of this directory information
428
* and the old information is deleted.
430
* @param dirInfo directory information
432
void FileListItem::setDirInfo(DirInfo* dirInfo)
439
QFileInfo fi(m_dirInfo->getDirname());
440
setText(0, fi.fileName());
446
* Update the icons according to the modificaton state and the tags present.
448
void FileListItem::updateIcons()
451
if (m_file->isChanged()) {
452
setPixmap(0, *modifiedPixmap);
454
static const QPixmap* tagpm[] = {
455
notagPixmap, v1Pixmap, v2Pixmap, v1v2Pixmap, nullPixmap
458
if (!m_file->isTagInformationRead()) {
462
if (m_file->hasTagV1()) {
465
if (m_file->hasTagV2()) {
469
setPixmap(0, *tagpm[tagpmIdx]);
475
* Update the text according to the file name.
477
void FileListItem::updateText()
480
setText(0, m_file->getFilename());
485
* Set directory name.
486
* Sets a new directory name if the item represents a directory.
488
* @param dirName new directory name
490
void FileListItem::setDirName(const QString& dirName)
493
m_dirInfo->setDirname(dirName);
494
QFileInfo fi(dirName);
495
setText(0, fi.fileName());