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
|
/***************************************************************************
sq_fileiconviewbase.cpp - description
-------------------
begin : ??? Feb 22 2005
copyright : (C) 2005 by Baryshev Dmitry
email : ksquirrel.iv@gmail.com
***************************************************************************/
/***************************************************************************
* *
* 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. *
* *
***************************************************************************/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <tqdragobject.h>
#include <tqcursor.h>
#include <tdeglobalsettings.h>
#include <tdeaction.h>
#include <tdefileitem.h>
#include <tdeio/job.h>
#include <konq_filetip.h>
#include "ksquirrel.h"
#include "sq_fileiconviewbase.h"
#include "sq_config.h"
SQ_FileIconViewBase::SQ_FileIconViewBase(TQWidget *parent, const char *name)
: KFileIconView(parent, name)
{
toolTip = new KonqFileTip(this);
slotResetToolTip();
disconnect(this, TQT_SIGNAL(onViewport()), this, 0);
disconnect(this, TQT_SIGNAL(onItem(TQIconViewItem *)), this, 0);
connect(this, TQT_SIGNAL(onViewport()), this, TQT_SLOT(slotRemoveToolTip()));
connect(this, TQT_SIGNAL(onItem(TQIconViewItem *)), this, TQT_SLOT(slotShowToolTip(TQIconViewItem *)));
}
SQ_FileIconViewBase::~SQ_FileIconViewBase()
{
slotRemoveToolTip();
}
void SQ_FileIconViewBase::slotResetToolTip()
{
SQ_Config::instance()->setGroup("Fileview");
toolTip->setOptions(true,
SQ_Config::instance()->readBoolEntry("tooltips_preview", false),
SQ_Config::instance()->readNumEntry("tooltips_lines", 6));
}
// Show extended tooltip for item under mouse cursor
void SQ_FileIconViewBase::slotShowToolTip(TQIconViewItem *item)
{
SQ_Config::instance()->setGroup("Fileview");
if(!SQ_Config::instance()->readBoolEntry("tooltips", false) ||
(!KSquirrel::app()->isActiveWindow() && SQ_Config::instance()->readBoolEntry("tooltips_inactive", true)))
return;
// remove previous tootip and stop timer
slotRemoveToolTip();
KFileIconViewItem *fitem = dynamic_cast<KFileIconViewItem *>(item);
if(!fitem) return;
KFileItem *f = fitem->fileInfo();
if(f) toolTip->setItem(f, fitem->rect(), fitem->pixmap());
}
bool SQ_FileIconViewBase::eventFilter(TQObject *o, TQEvent *e)
{
if(o == viewport() || o == this)
{
int type = e->type();
if(type == TQEvent::Leave || type == TQEvent::FocusOut || type == TQEvent::Hide)
slotRemoveToolTip();
}
return KFileIconView::eventFilter(o, e);
}
/*
* Remove tootip.
*/
void SQ_FileIconViewBase::slotRemoveToolTip()
{
toolTip->setItem(0);
}
// Accept drag
void SQ_FileIconViewBase::dragEnterEvent(TQDragEnterEvent *e)
{
e->accept(true);
}
/*
* Handle double clicks.
*/
void SQ_FileIconViewBase::contentsMouseDoubleClickEvent(TQMouseEvent *e)
{
TQIconView::contentsMouseDoubleClickEvent(e);
TQIconViewItem *item = findItem(e->pos());
// double click on item
if(item)
emit doubleClicked(item, e->globalPos());
// double click in viewport, lets invoke browser
else
emit invokeBrowser();
}
void SQ_FileIconViewBase::updateView(const KFileItem *i)
{
KFileIconViewItem *item = viewItem(i);
if(item)
initItemMy(item, i, true);
}
KFileIconViewItem* SQ_FileIconViewBase::viewItem(const KFileItem *item)
{
return item ? reinterpret_cast<KFileIconViewItem *>((void *)item->extraData(this)) : 0;
}
void SQ_FileIconViewBase::initItemMy(KFileIconViewItem *item, const KFileItem *i, bool upd)
{
if(upd)
item->setText(i->text(), true, true);
// determine current sorting type
TQDir::SortSpec spec = KFileView::sorting();
if(spec & TQDir::Time)
item->setKey(sortingKey((unsigned long)i->time(TDEIO::UDS_MODIFICATION_TIME), i->isDir(), spec));
else if(spec & TQDir::Size)
item->setKey(sortingKey(i->size(), i->isDir(), spec));
else
item->setKey(sortingKey(i->text(), i->isDir(), spec));
}
#include "sq_fileiconviewbase.moc"
|