PeriDyno 1.0.0
Loading...
Searching...
No Matches
QFilePathWidget.cpp
Go to the documentation of this file.
1#include "QFilePathWidget.h"
2
3#include "Field.h"
4#include "FilePath.h"
5
6#include <QHBoxLayout>
7#include <QFileDialog>
8#include <QMessageBox>
9
10namespace dyno
11{
14
17 {
19
20 //this->setStyleSheet("border:none");
21 QHBoxLayout* layout = new QHBoxLayout;
22 layout->setContentsMargins(0, 0, 0, 0);
23 layout->setSpacing(0);
24
25 this->setLayout(layout);
26
27 //Label
28 QLabel* name = new QLabel();
29 QString str = FormatFieldWidgetName(field->getObjectName());
30 name->setFixedSize(100, 18);
31 QFontMetrics fontMetrics(name->font());
32 QString elide = fontMetrics.elidedText(str, Qt::ElideRight, 100);
33 name->setText(elide);
34 //Set label tips
35 name->setToolTip(str);
36
37 fieldname = new QLineEdit;
38 fieldname->setText(QString::fromStdString(f->getValue()));
39
40 layout->addWidget(name, 0);
41 layout->addWidget(fieldname, 1);
42 layout->setSpacing(3);
43
44 connect(fieldname, &QLineEdit::textChanged, this, &QStringFieldWidget::updateField);
45 }
46
48 {
50 if (f == nullptr)
51 {
52 return;
53 }
54 f->setValue(str.toStdString());
55 f->update();
56 }
57
60 {
62
63 //this->setStyleSheet("border:none");
64 QHBoxLayout* layout = new QHBoxLayout;
65 layout->setContentsMargins(0, 0, 0, 0);
66 layout->setSpacing(0);
67
68 this->setLayout(layout);
69
70 //Label
71 QLabel* name = new QLabel();
72 QString str = FormatFieldWidgetName(field->getObjectName());
73 name->setFixedSize(100, 18);
74 QFontMetrics fontMetrics(name->font());
75 QString elide = fontMetrics.elidedText(str, Qt::ElideRight, 100);
76 name->setText(elide);
77 //Set label tips
78 name->setToolTip(str);
79
80 location = new QLineEdit;
81 location->setText(QString::fromStdString(f->getValue().string()));
82
83 QPushButton* open = new QPushButton("Open");
84// open->setStyleSheet("QPushButton{color: black; border-radius: 10px; border: 1px groove black;background-color:white; }"
85// "QPushButton:hover{background-color:white; color: black;}"
86// "QPushButton:pressed{background-color:rgb(85, 170, 255); border-style: inset; }" );
87 open->setFixedSize(60, 24);
88
89 layout->addWidget(name, 0);
90 layout->addWidget(location, 1);
91 layout->addWidget(open, 2);
92 layout->setSpacing(3);
93
94 connect(location, &QLineEdit::textChanged, this, &QFilePathWidget::updateField);
95
96 connect(open, &QPushButton::clicked, this, [=]() {
97
98 bool bPath = f->constDataPtr()->is_path();
99 if (bPath)
100 {
101 QString path = QFileDialog::getExistingDirectory(this, tr("Open File"), QString::fromStdString(getAssetPath()), QFileDialog::ReadOnly);
102 if (!path.isEmpty()) {
103 //Windows: "\\"; Linux: "/"
104 path = QDir::toNativeSeparators(path);
105 location->setText(path);
106 }
107 else
108 QMessageBox::warning(this, tr("Path"), tr("You do not select any path."));
109 }
110 else
111 {
112 QString path = QFileDialog::getOpenFileName(this, tr("Open File"), QString::fromStdString(getAssetPath()), tr("Text Files(*.*)"));
113 if (!path.isEmpty()) {
114 //Windows: "\\"; Linux: "/"
115 path = QDir::toNativeSeparators(path);
116 QFile file(path);
117 if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
118 QMessageBox::warning(this, tr("Read File"),
119 tr("Cannot open file:\n%1").arg(path));
120 return;
121 }
122 location->setText(path);
123 file.close();
124 }
125 else {
126 QMessageBox::warning(this, tr("Path"), tr("You do not select any file."));
127 }
128 }
129 });
130 }
131
133 {
135 if (f == nullptr)
136 {
137 return;
138 }
139
140 auto path = f->getValue();
141
142 path.set_path(str.toStdString());
143
144 f->setValue(path);
145 f->update();
146
147 emit fieldChanged();
148 }
149}
150
#define IMPL_FIELD_WIDGET(_data_type_, _type_)
T getValue()
Definition Field.h:130
std::shared_ptr< DataType > & constDataPtr()
Definition Field.h:80
QFieldWidget(FBase *field)
DECLARE_FIELD_WIDGET QFilePathWidget(FBase *field)
void updateField(QString str)
void updateField(QString str)
DECLARE_FIELD_WIDGET QStringFieldWidget(FBase *field)
TA * cast(TB *b)
Definition Typedef.inl:286
This is an implementation of AdditiveCCD based on peridyno.
Definition Array.h:25
DYN_FUNC Real arg(const Complex< Real > &)
Definition Complex.inl:273
QString FormatFieldWidgetName(std::string name)
Definition Format.cpp:9