summaryrefslogtreecommitdiffstats
path: root/quanta/dialogs/filecombo.cpp
blob: 404157577351c7dddd343b2e0ab1ad5fcab66c8e (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
/***************************************************************************
                          filecombo.cpp  -  description
                             -------------------
    begin                : Wed Sep 27 2000
    copyright            : (C) 2000 by Dmitry Poplavsky & Alexander Yakovlev & Eric Laffoon <pdima@users.sourceforge.net,yshurik@penguinpowered.com,sequitur@easystreet.com>
                           (C) 2002-2003 Andras Mantia <amantia@kde.org>
 ***************************************************************************/

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

// QT includes
#include <qlayout.h>
#include <qcombobox.h>
#include <qpushbutton.h>

// KDE includes
#include <klocale.h>
#include <kfiledialog.h>
#include <kurl.h>

// app include
#include "filecombo.h"
#include "qextfileinfo.h"

FileCombo::FileCombo(const KURL& a_baseURL, QWidget *parent, const char *name )
  :QWidget(parent,name)
{
  baseURL = a_baseURL;
  m_absolutePath = false;

  QHBoxLayout *layout = new QHBoxLayout(this);

  combo   = new QComboBox(true,this);
  combo->setEditable(true);
  button  = new QPushButton(this);

  button  ->setFixedSize(35,25);
  button  ->setText(i18n("..."));

  layout  ->addWidget( combo );
  layout  ->addWidget( button );

  connect( button, SIGNAL(clicked()), this, SLOT(slotFileSelect()) );
  connect( combo, SIGNAL(activated(const QString&)), SLOT(slotComboActivated(const QString&)));
  connect( combo, SIGNAL(textChanged(const QString&)), SLOT(slotComboActivated(const QString&)));
  setFocusProxy(combo);
}

FileCombo::FileCombo( QWidget *parent, const char *name )
   :QWidget( parent, name )
{
  baseURL.setPath(".");

  QHBoxLayout *layout = new QHBoxLayout(this);

  combo   = new QComboBox(true,this);
  button  = new QPushButton(this);

  button  ->setFixedSize(35,25);
  button  ->setText(i18n("..."));

  layout  ->addWidget( combo );
  layout  ->addWidget( button );

  connect( button, SIGNAL(clicked()), this, SLOT(slotFileSelect()) );
  connect( combo, SIGNAL(activated(const QString&)), SLOT(slotComboActivated(const QString&)));
  connect( combo, SIGNAL(textChanged(const QString&)), SLOT(slotComboActivated(const QString&)));
  setFocusProxy(combo);
}

FileCombo::~FileCombo(){
}

QString FileCombo::text() const
{
  return combo->currentText();
}

void FileCombo::setText( const QString &_txt )
{
  combo ->setEditText( _txt );
}

void FileCombo::slotFileSelect()
{
  KFileDialog *dlg = new KFileDialog(baseURL.url(), i18n("*|All Files"), this, "", true);
  dlg->setMode(KFile::File | KFile::Directory | KFile::ExistingOnly);
  dlg->exec();
  KURL url = dlg->selectedURL();
  delete dlg;
  if ( !url.isEmpty() )
  {
    if (!m_absolutePath) url = QExtFileInfo::toRelative(url, baseURL);
    combo->setEditText( url.path() );
  }
}

/** No descriptions */
void FileCombo::setBaseURL(const KURL& a_baseURL)
{
 baseURL = a_baseURL;
}

/** No descriptions */
void FileCombo::setReturnAbsolutePath(bool absolutePath)
{
 m_absolutePath = absolutePath;
}

void FileCombo::slotComboActivated(const QString&s)
{
  emit activated(s);
}

#include "filecombo.moc"