summaryrefslogtreecommitdiffstats
path: root/src/hitwidget.cpp
blob: 5ad364b564871f6c1cc12cae6cf319cac2686135 (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
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
/***************************************************************************
 *   Copyright (C) 2005 Novell, Inc.                                       *
 *                                                                         *
 *   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.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA           *
 ***************************************************************************/

#include <tqscrollview.h>
#include <tqcombobox.h>
#include <tqtoolbutton.h>
#include <tqlayout.h>

#include <kpushbutton.h>
#include <kdebug.h>
#include <kiconloader.h>
#include <tdelocale.h>
#include <kurllabel.h>
#include <tdeglobalsettings.h>

/*#include <konq_filetip.h>*/

#include "hitwidget.h"
#include "kerrylabel.h"


HitWidget::HitWidget(TQString uri, TQString mimetype, KWidgetListbox *parent, const char *name)
  : HitWidgetLayout(parent, name), m_uri(uri), m_mimetype(mimetype), m_collapsed(false),
    m_was_collapsed(false), m_icon(TQString::null)
{
  HitWidgetLayoutLayout->setMargin(4);
  toolButton1->setEnabled(false);
  toolButton1->hide();
  score->setHidden(true);
  //score->setText("");
  setDescriptionText("");
  setPropertiesText("");
  icon->installEventFilter(this);
/*  pFileTip = new KonqFileTip(parent);*/
/*  pFileTip->setItem(0L);*/
  qsv=parent;

}

HitWidget::~HitWidget()
{
/*  delete pFileTip;*/
}

void HitWidget::setIcon(const TQString name)
{
  m_icon = name;
  if (m_collapsed)
    icon->setPixmap(TDEGlobal::iconLoader()->loadIcon(m_icon, TDEIcon::NoGroup, TDEIcon::SizeSmall));
  else
    icon->setPixmap(TDEGlobal::iconLoader()->loadIcon(m_icon, TDEIcon::NoGroup, TDEIcon::SizeLarge));
}

void HitWidget::toggleCollapsed()
{
  setCollapsed(!m_collapsed);
}

void HitWidget::setCollapsed(bool collapsed)
{
  if (m_collapsed==collapsed)
    return;

  if (collapsed) {
    toolButton1->setEnabled(true);
    m_was_collapsed = true;
    icon->setPixmap(TDEGlobal::iconLoader()->loadIcon(m_icon, TDEIcon::NoGroup, TDEIcon::SizeSmall));
#if 0
    i18n("Expand");
    i18n("Collapse");
    i18n("Expand All");
    i18n("Collapse All");
    i18n("(still searching)");
#endif
    toolButton1->setIconSet(SmallIconSet("application-vnd.tde.info"));
    description->setHidden(true);
    properties->setHidden(true);
    score->setHidden(true);
    icon->setMinimumSize( TQSize( 64, 16 ) );
    icon->setMaximumSize( TQSize( 64, 16 ) );
    m_collapsed = collapsed;
  }
  else {
    icon->setPixmap(TDEGlobal::iconLoader()->loadIcon(m_icon, TDEIcon::NoGroup, TDEIcon::SizeLarge));
    toolButton1->setIconSet(SmallIconSet("2uparrow"));
    description->setHidden(false);
    properties->setHidden(false);
    //score->setHidden(false);
    icon->setMinimumSize( TQSize( 64, 64 ) );
    icon->setMaximumSize( TQSize( 64, 64 ) );
    m_collapsed = collapsed;
    emit uncollapsed(this);
  }

  if (qsv)
     qsv->adjustSize(this);
}

bool HitWidget::isCollapsed() const
{
  return m_collapsed;
}

void HitWidget::setDescriptionText(TQString text)
{
  description->setText(text);
}

void HitWidget::setPropertiesText(TQString text)
{
  properties->setText(text);
}

void HitWidget::insertHeaderWidget( int index, TQWidget * widget)
{
  layoutHeader->insertWidget(index,widget);
}

void HitWidget::insertHitWidget( int index, TQWidget * widget)
{
  layoutButton->insertWidget(index,widget);
}

void HitWidget::insertTextWidget( int index, TQWidget * widget)
{
  layoutText->insertWidget(index,widget);
}

void HitWidget::insertHitSpacing( int index, int size)
{
  layoutButton->insertSpacing(index,size);
}

TQString HitWidget::uri() const
{
  return m_uri;
}

void HitWidget::setUri(const TQString uri)
{
/*  pFileTip->setItem(0L);*/
  m_uri = uri;
}

TQString HitWidget::mimetype() const
{
  return m_mimetype;
}

void HitWidget::adjustSize()
{
  int dwidth, pwidth;

  HitWidgetLayout::adjustSize();
  if (m_was_collapsed) {
     dwidth = width()-160;
     pwidth = width()-160;
  }
  else {
     dwidth = description->size().width() + 160;
     pwidth = properties->size().width() + 160;
  }

  description->setFixedSize(dwidth,description->heightForWidth(dwidth));
  properties->setFixedSize(pwidth,properties->heightForWidth(pwidth));
  HitWidgetLayout::adjustSize();
}

bool HitWidget::eventFilter( TQObject *, TQEvent * )
{
/*  if ( obj == icon && !m_uri.isEmpty() ) {
    if ( ev->type() == TQEvent::Enter && parent() ) {
      pFileTip->setOptions(true, true, 6);
      KFileItem *fileitem=new KFileItem(m_uri,m_mimetype,KFileItem::Unknown);
      TQPoint viewport = qsv->viewport()->mapFromGlobal(mapToGlobal(icon->pos()));
      TQRect qr(qsv->viewportToContents(viewport),TQSize(icon->width()*2,icon->height()));
      pFileTip->setItem(fileitem,qr,icon->pixmap());
    }
    else if ( ev->type() == TQEvent::Leave )
      pFileTip->setItem(0L);
    return HitWidgetLayout::eventFilter( obj, ev );
  }*/
  return false;
}

void HitWidget::changeTerminalUrl(int ) {

    TQString app = score->currentText();
    TQString title = shellTitles[score->currentText()];

    icon->setURL(TQString("%1 %2").arg(app).arg(title));

}

#include "hitwidget.moc"