121 lines
4.0 KiB
C++
121 lines
4.0 KiB
C++
/****************************************************************************
|
|
**
|
|
** Copyright (C) 2006 Trolltech ASA. All rights reserved.
|
|
**
|
|
** This file is part of the documentation of Qt. It was originally
|
|
** published as part of Qt Quarterly.
|
|
**
|
|
** This file may be used under the terms of the GNU General Public License
|
|
** version 2.0 as published by the Free Software Foundation or under the
|
|
** terms of the Qt Commercial License Agreement. The respective license
|
|
** texts for these are provided with the open source and commercial
|
|
** editions of Qt.
|
|
**
|
|
** If you are unsure which license is appropriate for your use, please
|
|
** review the following information:
|
|
** http://www.trolltech.com/products/qt/licensing.html or contact the
|
|
** sales department at sales@trolltech.com.
|
|
**
|
|
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
|
|
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
|
**
|
|
****************************************************************************/
|
|
|
|
#include "fileedit.h"
|
|
#include <QHBoxLayout>
|
|
#include <QToolButton>
|
|
#include <QFileDialog>
|
|
#include <QFocusEvent>
|
|
#include "selectlinedialog.h"
|
|
|
|
extern QString g_SelectLine_filePath;
|
|
|
|
FileEdit::FileEdit(QWidget *parent)
|
|
: QWidget(parent)
|
|
{
|
|
QHBoxLayout *layout = new QHBoxLayout(this);
|
|
layout->setMargin(0);
|
|
layout->setSpacing(0);
|
|
theLineEdit = new QLineEdit(this);
|
|
theLineEdit->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred));
|
|
theLineEdit->setReadOnly(true);//只读
|
|
QToolButton *button = new QToolButton(this);
|
|
button->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred));
|
|
button->setText(QLatin1String("..."));
|
|
layout->addWidget(theLineEdit);
|
|
layout->addWidget(button);
|
|
setFocusProxy(theLineEdit);
|
|
setFocusPolicy(Qt::StrongFocus);
|
|
setAttribute(Qt::WA_InputMethodEnabled);
|
|
connect(theLineEdit, SIGNAL(textEdited(const QString &)),
|
|
this, SIGNAL(filePathChanged(const QString &)));
|
|
connect(button, SIGNAL(clicked()),
|
|
this, SLOT(buttonClicked()));
|
|
}
|
|
|
|
void FileEdit::buttonClicked()
|
|
{
|
|
if(theFilter.contains("slf.Line"))
|
|
{
|
|
QStringList listTmp = theFilter.split("@@");
|
|
if(listTmp.size()>3)
|
|
{
|
|
QString strSlfName = listTmp[1];
|
|
QString strWellName = listTmp[2];
|
|
QString strType = listTmp[3];
|
|
// 创建对话框
|
|
SelectLineDialog *dlg = new SelectLineDialog(nullptr);
|
|
dlg->setInfo(strSlfName, strWellName, strType);
|
|
//
|
|
dlg->setAttribute(Qt::WA_DeleteOnClose);//关闭时,自动删除窗口对象
|
|
int result = dlg->exec();//模态对话框
|
|
if (result == QDialog::Accepted) {
|
|
// 处理用户点击了确定按钮的逻辑
|
|
QString filePath = g_SelectLine_filePath + "@" + strSlfName;
|
|
theLineEdit->setText(filePath);
|
|
emit filePathChanged(filePath);
|
|
}
|
|
else if (result == QDialog::Rejected) {
|
|
// 处理用户点击了取消按钮的逻辑
|
|
}
|
|
else {
|
|
// 处理其他情况的逻辑
|
|
}
|
|
}
|
|
}
|
|
else{
|
|
QString filePath = QFileDialog::getOpenFileName(this, tr("选择文件"), strFilePath, theFilter);
|
|
if (filePath.isNull())
|
|
return;
|
|
|
|
QFileInfo finfo(filePath);
|
|
theLineEdit->setText(finfo.baseName());
|
|
emit filePathChanged(filePath);
|
|
}
|
|
}
|
|
|
|
void FileEdit::focusInEvent(QFocusEvent *e)
|
|
{
|
|
theLineEdit->event(e);
|
|
if (e->reason() == Qt::TabFocusReason || e->reason() == Qt::BacktabFocusReason) {
|
|
theLineEdit->selectAll();
|
|
}
|
|
QWidget::focusInEvent(e);
|
|
}
|
|
|
|
void FileEdit::focusOutEvent(QFocusEvent *e)
|
|
{
|
|
theLineEdit->event(e);
|
|
QWidget::focusOutEvent(e);
|
|
}
|
|
|
|
void FileEdit::keyPressEvent(QKeyEvent *e)
|
|
{
|
|
theLineEdit->event(e);
|
|
}
|
|
|
|
void FileEdit::keyReleaseEvent(QKeyEvent *e)
|
|
{
|
|
theLineEdit->event(e);
|
|
}
|