Skip to content

Commit

Permalink
Merge pull request #2 from ProgramCX/main
Browse files Browse the repository at this point in the history
Create Basic UI
  • Loading branch information
L-Super authored Aug 26, 2024
2 parents 5ce388b + 8030e09 commit 694b653
Show file tree
Hide file tree
Showing 26 changed files with 1,663 additions and 28 deletions.
9 changes: 7 additions & 2 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,12 @@ message(STATUS "Qt deployment tool: ${QT_DEPLOY_EXECUTABLE}")

qt_add_resources(QRC_FILES resources.qrc)

set(SRC_FILES MainWindow.cpp MainWindow.h MainWindow.ui)
set(SRC_FILES MainWindow.cpp MainWindow.h MainWindow.ui
DownloadListWidget.cpp DownloadListWidget.h DownloadListWidget.ui
DownloadItemWidget.cpp DownloadItemWidget.h DownloadItemWidget.ui
HelpWidget.cpp HelpWidget.h HelpWidget.ui
SettingsWidget.cpp SettingsWidget.h SettingsWidget.ui
)

set(APP_DESCRIPTION "An Efficient Multi-threaded Download Manager")
set(APP_COPYRIGHT "Copyright 2024-2077 The FlowD Ltd.")
Expand Down Expand Up @@ -128,4 +133,4 @@ elseif (APPLE)
"$<TARGET_BUNDLE_DIR:${PROJECT_NAME}>"
# -dmg
)
endif ()
endif ()
30 changes: 30 additions & 0 deletions src/DownloadItemWidget.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#include "DownloadItemWidget.h"
#include "ui_DownloadItemWidget.h"

DownloadItemWidget::DownloadItemWidget(QWidget* parent) : QWidget(parent), ui(new Ui::DownloadItemWidget)
{
ui->setupUi(this);
connectSlots();
}

void DownloadItemWidget::connectSlots()
{
connect(ui->btnSuspend, &QPushButton::clicked, this, &DownloadItemWidget::onBtnSuspendClicked);
}

void DownloadItemWidget::onBtnSuspendClicked(bool checked)
{
if (checked) {
ui->btnSuspend->setText("继续");
//TODO:暂停下载的逻辑
}
else {
ui->btnSuspend->setText("暂停");
//TODO:开始下载的逻辑
}
}

DownloadItemWidget::~DownloadItemWidget()
{
delete ui;
}
25 changes: 25 additions & 0 deletions src/DownloadItemWidget.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#pragma once

#include <QWidget>

QT_BEGIN_NAMESPACE
namespace Ui {
class DownloadItemWidget;
}
QT_END_NAMESPACE

class DownloadItemWidget : public QWidget {
Q_OBJECT

public:
explicit DownloadItemWidget(QWidget* parent = nullptr);
~DownloadItemWidget() override;

protected slots:
void onBtnSuspendClicked(bool checked);

private:
Ui::DownloadItemWidget* ui;

void connectSlots();
};
206 changes: 206 additions & 0 deletions src/DownloadItemWidget.ui
Original file line number Diff line number Diff line change
@@ -0,0 +1,206 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>DownloadItemWidget</class>
<widget class="QWidget" name="DownloadItemWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>718</width>
<height>178</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QFrame" name="frame">
<property name="styleSheet">
<string notr="true"/>
</property>
<property name="frameShape">
<enum>QFrame::Shape::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Shadow::Raised</enum>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLabel" name="labFileName">
<property name="minimumSize">
<size>
<width>20</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>21</height>
</size>
</property>
<property name="text">
<string>// 文件名称</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Orientation::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Policy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>200</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="btnSuspend">
<property name="minimumSize">
<size>
<width>61</width>
<height>31</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>61</width>
<height>31</height>
</size>
</property>
<property name="cursor">
<cursorShape>PointingHandCursor</cursorShape>
</property>
<property name="text">
<string>暂停</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="btnDelete">
<property name="minimumSize">
<size>
<width>61</width>
<height>31</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>61</width>
<height>31</height>
</size>
</property>
<property name="cursor">
<cursorShape>PointingHandCursor</cursorShape>
</property>
<property name="text">
<string>删除</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QLabel" name="labFileSize">
<property name="minimumSize">
<size>
<width>181</width>
<height>21</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>21</height>
</size>
</property>
<property name="text">
<string>文件大小</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="labRemainTime">
<property name="minimumSize">
<size>
<width>201</width>
<height>21</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>21</height>
</size>
</property>
<property name="text">
<string>剩余时间</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="labSpeed">
<property name="minimumSize">
<size>
<width>211</width>
<height>21</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>21</height>
</size>
</property>
<property name="text">
<string>下载速度</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QProgressBar" name="progressBar">
<property name="minimumSize">
<size>
<width>621</width>
<height>20</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>20</height>
</size>
</property>
<property name="value">
<number>24</number>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
62 changes: 62 additions & 0 deletions src/DownloadListWidget.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#include "DownloadListWidget.h"
#include "ui_DownloadListWidget.h"

#include <QListWidgetItem>

#include "DownloadItemWidget.h"

DownloadListWidget::DownloadListWidget(QWidget* parent) : QWidget(parent), ui(new Ui::DownloadListWidget)
{
ui->setupUi(this);

//仅供测试
QListWidgetItem* pItem = new QListWidgetItem(ui->listWidget);
ui->listWidget->addItem(pItem);

DownloadItemWidget* aCustomItem = new DownloadItemWidget;
ui->listWidget->setItemWidget(pItem, aCustomItem);
ui->listWidget->setCurrentItem(pItem);

iniUi();
connectSlots();
}

void DownloadListWidget::iniUi()
{
//初次选中“下载中”
ui->btnTabDownloading->setChecked(true);
changeTab(0);
}

void DownloadListWidget::connectSlots()
{
connect(ui->btnTabDownloading, &QPushButton::clicked, this, [=](bool checked) {
if (checked)
changeTab(0);
else
ui->btnTabDownloading->setChecked(true);
});
connect(ui->btnTabStopped, &QPushButton::clicked, this, [=](bool checked) {
if (checked)
changeTab(1);
else
ui->btnTabStopped->setChecked(true);
});
}

void DownloadListWidget::changeTab(int index)
{
if (index == 0) {
ui->btnTabStopped->setChecked(false);
//TODO:过滤下载条目
}
else if (index == 1) {
ui->btnTabDownloading->setChecked(false);
//TODO:过滤下载条目
}
}

DownloadListWidget::~DownloadListWidget()
{
delete ui;
}
24 changes: 24 additions & 0 deletions src/DownloadListWidget.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#pragma once

#include <QWidget>

QT_BEGIN_NAMESPACE
namespace Ui {
class DownloadListWidget;
}
QT_END_NAMESPACE

class DownloadListWidget : public QWidget {
Q_OBJECT

public:
explicit DownloadListWidget(QWidget* parent = nullptr);
~DownloadListWidget() override;

private:
Ui::DownloadListWidget* ui;

void iniUi();
void connectSlots();
void changeTab(int index);
};
Loading

0 comments on commit 694b653

Please sign in to comment.