ENH: Add cross compiling support in the GUI in the same dialog that prompts for
[cmake.git] / Source / QtDialog / QCMakeWidgets.cxx
blob1092c88cda0fda840f615fea7449d7cad1e4678d
1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: QCMakeWidgets.cxx,v $
5 Language: C++
6 Date: $Date: 2008-05-15 23:21:01 $
7 Version: $Revision: 1.1 $
9 Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
10 See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
12 This software is distributed WITHOUT ANY WARRANTY; without even
13 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 PURPOSE. See the above copyright notices for more information.
16 =========================================================================*/
18 #include "QCMakeWidgets.h"
20 #include <QDirModel>
21 #include <QFileInfo>
22 #include <QFileDialog>
23 #include <QToolButton>
24 #include <QResizeEvent>
26 QCMakeFileEditor::QCMakeFileEditor(QWidget* p, const QString& var)
27 : QLineEdit(p), Variable(var)
29 this->ToolButton = new QToolButton(this);
30 this->ToolButton->setText("...");
31 this->ToolButton->setCursor(QCursor(Qt::ArrowCursor));
32 QObject::connect(this->ToolButton, SIGNAL(clicked(bool)),
33 this, SLOT(chooseFile()));
36 QCMakeFilePathEditor::QCMakeFilePathEditor(QWidget* p, const QString& var)
37 : QCMakeFileEditor(p, var)
39 this->setCompleter(new QCMakeFileCompleter(this, false));
42 QCMakePathEditor::QCMakePathEditor(QWidget* p, const QString& var)
43 : QCMakeFileEditor(p, var)
45 this->setCompleter(new QCMakeFileCompleter(this, true));
48 void QCMakeFileEditor::resizeEvent(QResizeEvent* e)
50 // make the tool button fit on the right side
51 int h = e->size().height();
52 // move the line edit to make room for the tool button
53 this->setContentsMargins(0, 0, h, 0);
54 // put the tool button in its place
55 this->ToolButton->resize(h, h);
56 this->ToolButton->move(this->width() - h, 0);
59 void QCMakeFilePathEditor::chooseFile()
61 // choose a file and set it
62 QString path;
63 QFileInfo info(this->text());
64 QString title;
65 if(this->Variable.isEmpty())
67 title = tr("Select File");
69 else
71 title = tr("Select File for %1");
72 title = title.arg(this->Variable);
74 this->fileDialogExists(true);
75 path = QFileDialog::getOpenFileName(this, title, info.absolutePath());
76 this->fileDialogExists(false);
78 if(!path.isEmpty())
80 this->setText(QDir::fromNativeSeparators(path));
84 void QCMakePathEditor::chooseFile()
86 // choose a file and set it
87 QString path;
88 QString title;
89 if(this->Variable.isEmpty())
91 title = tr("Select Path");
93 else
95 title = tr("Select Path for %1");
96 title = title.arg(this->Variable);
98 this->fileDialogExists(true);
99 path = QFileDialog::getExistingDirectory(this, title, this->text());
100 this->fileDialogExists(false);
101 if(!path.isEmpty())
103 this->setText(QDir::fromNativeSeparators(path));
107 QCMakeFileCompleter::QCMakeFileCompleter(QObject* o, bool dirs)
108 : QCompleter(o)
110 QDirModel* model = new QDirModel(this);
111 if(dirs)
113 model->setFilter(QDir::AllDirs | QDir::Drives | QDir::NoDotAndDotDot);
115 this->setModel(model);
118 QString QCMakeFileCompleter::pathFromIndex(const QModelIndex& idx) const
120 return QDir::fromNativeSeparators(QCompleter::pathFromIndex(idx));