HAL
open_file_widget.cpp
Go to the documentation of this file.
2 
8 
9 #include <QDebug>
10 #include <QDragEnterEvent>
11 #include <QLabel>
12 #include <QMimeData>
13 #include <QStyle>
14 #include <QVBoxLayout>
15 
16 namespace hal
17 {
18  OpenFileWidget::OpenFileWidget(QWidget* parent) : QFrame(parent), mLayout(new QVBoxLayout()), mTextLabel(new QLabel()), mIconLabel(new QLabel()), mDragActive(false)
19  {
20  setAcceptDrops(true);
21 
22  mTextLabel->setObjectName("text-label");
23  mTextLabel->setText("Open an existing project or create a new one by dropping a project folder or netlist file here.");
24  mTextLabel->setWordWrap(true);
25 
26  mIconLabel->setObjectName("icon-label");
29 
30  setLayout(mLayout);
31  mLayout->setContentsMargins(0, 0, 0, 0);
32  mLayout->setSpacing(0);
33  mLayout->addWidget(mTextLabel);
34  mLayout->addWidget(mIconLabel);
35  }
36 
38  {
39  const QMimeData* mime_data = event->mimeData();
40  if (mime_data->hasUrls())
41  {
42  event->acceptProposedAction();
43  mDragActive = true;
44  repolish();
45  }
46  }
47 
49  {
50  Q_UNUSED(event)
51 
52  mDragActive = false;
53  repolish();
54  }
55 
57  {
58  // pass url list to file manager and check for matching file extensions,
59  //if match found -> show progress screen else do nothing
60  const QMimeData* mime_data = event->mimeData();
61  if (mime_data->hasUrls())
62  {
63  // QStringList path_list;
64  // QList<QUrl> url_list = mime_data->urls();
65 
66  // if (url_list.size() > 1)
67  // return;
68 
69  QString file = mime_data->urls().at(0).toLocalFile();
70  if (QFileInfo(file).suffix().toLower()=="zip")
71  {
72  qDebug() << "zip file" << file;
73  ImportProjectDialog ipd(this);
74  ipd.setZippedFile(file);
75  if (ipd.exec() == QDialog::Accepted)
76  {
77  if (ipd.importProject())
78  {
81  act->exec();
82  }
83  else
85  "Import Project Failed",
86  "Failed to extract a HAL project from selected archive file.\n"
87  "You might want to uncompress the archive manually and try to fetchGateLibrary the project.");
88  }
89  }
90 
92 
93  switch (stat)
94  {
97  break;
99  log_warning("gui", "directory {} is not a hal project.", file.toStdString());
100  break;
101  case FileManager::IsFile:
103  break;
104  default:
105  log_warning("gui", "cannot open nor import {}.", file.toStdString());
106  break;
107  }
108 
109  // for (int i = 0; i < url_list.size() && i < 32; ++i)
110  // {
111  // path_list.append(url_list.at(i).toLocalFile());
112  // }
113 
114  event->acceptProposedAction();
115  mDragActive = false;
116  repolish();
117  }
118  }
119 
121  {
122  return mDragActive;
123  }
124 
126  {
127  return mIconStyle;
128  }
129 
131  {
132  return mIconPath;
133  }
134 
136  {
137  mIconStyle = style;
138  }
139 
141  {
142  mIconPath = path;
143  }
144 
146  {
147  QStyle* s = style();
148 
149  s->unpolish(this);
150  s->polish(this);
151 
152  if (!mIconPath.isEmpty())
153  mIconLabel->setPixmap(gui_utility::getStyledSvgIcon(mIconStyle, mIconPath).pixmap(QSize(120, 120)));
154  }
155 } // namespace hal
then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file
void importFile(QString filename)
void openProject(QString projPath)
static FileManager * get_instance()
static DirectoryStatus directoryStatus(const QString &pathname)
QString extractedProjectAbsolutePath() const
void setZippedFile(const QString &filename)
void setIconPath(const QString &path)
void dragLeaveEvent(QDragLeaveEvent *event) override
OpenFileWidget(QWidget *parent=nullptr)
void setIconStyle(const QString &style)
void dragEnterEvent(QDragEnterEvent *event) override
void dropEvent(QDropEvent *event) override
#define log_warning(channel,...)
Definition: log.h:76
QIcon getStyledSvgIcon(const QString &from_to_colors_enabled, const QString &svg_path, QString from_to_colors_disabled=QString())
Definition: graphics.cpp:60
void addWidget(QWidget *widget, int stretch, Qt::Alignment alignment)
void setSpacing(int spacing)
virtual int exec()
virtual bool event(QEvent *e) override
void setAlignment(Qt::Alignment)
void setPixmap(const QPixmap &)
void setText(const QString &)
void setWordWrap(bool on)
void setContentsMargins(int left, int top, int right, int bottom)
QMessageBox::StandardButton warning(QWidget *parent, const QString &title, const QString &text, QMessageBox::StandardButtons buttons, QMessageBox::StandardButton defaultButton)
bool hasUrls() const const
QList< QUrl > urls() const const
void setObjectName(const QString &name)
bool isEmpty() const const
virtual void polish(QWidget *widget)
virtual void unpolish(QWidget *widget)
AlignHCenter
void setAcceptDrops(bool on)
void setLayout(QLayout *layout)
void setSizePolicy(QSizePolicy)
QStyle * style() const const