HAL
open_file_widget.cpp
Go to the documentation of this file.
2 
6 
7 #include <QDragEnterEvent>
8 #include <QLabel>
9 #include <QMimeData>
10 #include <QStyle>
11 #include <QVBoxLayout>
12 
13 namespace hal
14 {
15  OpenFileWidget::OpenFileWidget(QWidget* parent) : QFrame(parent), mLayout(new QVBoxLayout()), mTextLabel(new QLabel()), mIconLabel(new QLabel()), mDragActive(false)
16  {
17  setAcceptDrops(true);
18 
19  mTextLabel->setObjectName("text-label");
20  mTextLabel->setText("Open an existing project or create a new one by dropping a project folder or netlist file here.");
21  mTextLabel->setWordWrap(true);
22 
23  mIconLabel->setObjectName("icon-label");
26 
27  setLayout(mLayout);
28  mLayout->setContentsMargins(0, 0, 0, 0);
29  mLayout->setSpacing(0);
30  mLayout->addWidget(mTextLabel);
31  mLayout->addWidget(mIconLabel);
32  }
33 
35  {
36  const QMimeData* mime_data = event->mimeData();
37  if (mime_data->hasUrls())
38  {
39  event->acceptProposedAction();
40  mDragActive = true;
41  repolish();
42  }
43  }
44 
46  {
47  Q_UNUSED(event)
48 
49  mDragActive = false;
50  repolish();
51  }
52 
54  {
55  // pass url list to file manager and check for matching file extensions,
56  //if match found -> show progress screen else do nothing
57  const QMimeData* mime_data = event->mimeData();
58  if (mime_data->hasUrls())
59  {
60  // QStringList path_list;
61  // QList<QUrl> url_list = mime_data->urls();
62 
63  // if (url_list.size() > 1)
64  // return;
65 
66  QString file = mime_data->urls().at(0).toLocalFile();
68 
69  switch (stat)
70  {
73  break;
75  log_warning("gui", "directory {} is not a hal project.", file.toStdString());
76  break;
79  break;
80  default:
81  log_warning("gui", "cannot open nor import {}.", file.toStdString());
82  break;
83  }
84 
85  // for (int i = 0; i < url_list.size() && i < 32; ++i)
86  // {
87  // path_list.append(url_list.at(i).toLocalFile());
88  // }
89 
90  event->acceptProposedAction();
91  mDragActive = false;
92  repolish();
93  }
94  }
95 
97  {
98  return mDragActive;
99  }
100 
102  {
103  return mIconStyle;
104  }
105 
107  {
108  return mIconPath;
109  }
110 
112  {
113  mIconStyle = style;
114  }
115 
117  {
118  mIconPath = path;
119  }
120 
122  {
123  QStyle* s = style();
124 
125  s->unpolish(this);
126  s->polish(this);
127 
128  if (!mIconPath.isEmpty())
129  mIconLabel->setPixmap(gui_utility::getStyledSvgIcon(mIconStyle, mIconPath).pixmap(QSize(120, 120)));
130  }
131 } // 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)
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 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)
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