source: trunk/examples/help/simpletextviewer/findfiledialog.cpp@ 321

Last change on this file since 321 was 2, checked in by Dmitry A. Kuminov, 16 years ago

Initially imported qt-all-opensource-src-4.5.1 from Trolltech.

File size: 7.1 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4** Contact: Qt Software Information ([email protected])
5**
6** This file is part of the examples of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial Usage
10** Licensees holding valid Qt Commercial licenses may use this file in
11** accordance with the Qt Commercial License Agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and Nokia.
14**
15** GNU Lesser General Public License Usage
16** Alternatively, this file may be used under the terms of the GNU Lesser
17** General Public License version 2.1 as published by the Free Software
18** Foundation and appearing in the file LICENSE.LGPL included in the
19** packaging of this file. Please review the following information to
20** ensure the GNU Lesser General Public License version 2.1 requirements
21** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
22**
23** In addition, as a special exception, Nokia gives you certain
24** additional rights. These rights are described in the Nokia Qt LGPL
25** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
26** package.
27**
28** GNU General Public License Usage
29** Alternatively, this file may be used under the terms of the GNU
30** General Public License version 3.0 as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL included in the
32** packaging of this file. Please review the following information to
33** ensure the GNU General Public License version 3.0 requirements will be
34** met: http://www.gnu.org/copyleft/gpl.html.
35**
36** If you are unsure which license is appropriate for your use, please
37** contact the sales department at [email protected].
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42#include <QtCore/QDir>
43#include <QtGui/QLayout>
44#include <QtGui/QComboBox>
45#include <QtGui/QTreeWidget>
46#include <QtGui/QLayout>
47#include <QtGui/QFileDialog>
48#include <QtGui/QDialogButtonBox>
49#include <QtGui/QToolButton>
50#include <QtGui/QPushButton>
51#include <QtGui/QLabel>
52
53#include "findfiledialog.h"
54#include "assistant.h"
55#include "textedit.h"
56
57//! [0]
58FindFileDialog::FindFileDialog(TextEdit *editor, Assistant *assistant)
59 : QDialog(editor)
60{
61 currentAssistant = assistant;
62 currentEditor = editor;
63//! [0]
64
65 createButtons();
66 createComboBoxes();
67 createFilesTree();
68 createLabels();
69 createLayout();
70
71 directoryComboBox->addItem(QDir::toNativeSeparators(QDir::currentPath()));
72 fileNameComboBox->addItem("*");
73 findFiles();
74
75 setWindowTitle(tr("Find File"));
76//! [1]
77}
78//! [1]
79
80void FindFileDialog::browse()
81{
82 QString currentDirectory = directoryComboBox->currentText();
83 QString newDirectory = QFileDialog::getExistingDirectory(this,
84 tr("Select Directory"), currentDirectory);
85 if (!newDirectory.isEmpty()) {
86 directoryComboBox->addItem(QDir::toNativeSeparators(newDirectory));
87 directoryComboBox->setCurrentIndex(directoryComboBox->count() - 1);
88 update();
89 }
90}
91
92//! [2]
93void FindFileDialog::help()
94{
95 currentAssistant->showDocumentation("filedialog.html");
96}
97//! [2]
98
99void FindFileDialog::openFile(QTreeWidgetItem *item)
100{
101 if (!item) {
102 item = foundFilesTree->currentItem();
103 if (!item)
104 return;
105 }
106
107 QString fileName = item->text(0);
108 QString path = directoryComboBox->currentText() + QDir::separator();
109
110 currentEditor->setContents(path + fileName);
111 close();
112}
113
114void FindFileDialog::update()