Skip to content

Commit

Permalink
Always use native window for file browser dialog.
Browse files Browse the repository at this point in the history
  • Loading branch information
lins05 committed May 2, 2017
1 parent 2ac96b3 commit 52a7acf
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 114 deletions.
27 changes: 0 additions & 27 deletions qt.css
Original file line number Diff line number Diff line change
Expand Up @@ -417,33 +417,6 @@ FileBrowserDialog {
min-height: 456px;
}

FileBrowserDialog QSizeGrip {
margin-right: 2px;
}

FileBrowserDialog QWidget#mainWidget {
border: 1px solid #333;
border-radius: 5px;
background-color: #f2f2f2;
}

FileBrowserDialog QWidget#mHeader {
min-height: 15px;
max-height: 30px;
margin-left: 10px;
margin-right: 10px;
padding-bottom: 1px;
}

FileBrowserDialog QWidget#mHeader QLabel {
padding-left: 60px;
margin-left: 4px;
}

FileBrowserDialog QWidget#mHeader QPushButton {
margin-left: 4px;
}

FileBrowserDialog QToolBar#topBar {
border: 0;
border-bottom: 1px solid #d0d0d0;
Expand Down
84 changes: 4 additions & 80 deletions src/filebrowser/file-browser-dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,24 +95,14 @@ FileBrowserDialog::FileBrowserDialog(const Account &account, const ServerRepo& r

Qt::WindowFlags flags =
(windowFlags() & ~Qt::WindowContextHelpButtonHint & ~Qt::Dialog) |
Qt::Window | Qt::WindowSystemMenuHint;
Qt::Window | Qt::WindowSystemMenuHint | Qt::CustomizeWindowHint |
Qt::WindowMinimizeButtonHint | Qt::WindowCloseButtonHint |
Qt::WindowMaximizeButtonHint;

if (shouldUseFramelessWindow()) {
flags |= Qt::FramelessWindowHint;
} else {
flags |= Qt::CustomizeWindowHint | Qt::WindowMinimizeButtonHint |
Qt::WindowCloseButtonHint | Qt::WindowMaximizeButtonHint;
}
setWindowFlags(flags);

if (shouldUseFramelessWindow()) {
resizer_ = new QSizeGrip(this);
resizer_->resize(resizer_->sizeHint());
}

setAttribute(Qt::WA_TranslucentBackground, true);
// setAttribute(Qt::WA_TranslucentBackground, true);

createTitleBar();
createToolBar();
createStatusBar();
createLoadingFailedView();
Expand All @@ -137,16 +127,10 @@ FileBrowserDialog::FileBrowserDialog(const Account &account, const ServerRepo& r
stack_->insertWidget(INDEX_LOADING_FAILED_VIEW, loading_failed_view_);
stack_->setContentsMargins(0, 0, 0, 0);

vlayout->addWidget(header_);
vlayout->addWidget(toolbar_);
vlayout->addWidget(stack_);
vlayout->addWidget(status_bar_);

if (!shouldUseFramelessWindow()) {
header_->setVisible(false);
setStyleSheet("FileBrowserDialog QWidget#mainWidget {border : 0; border-radius: 0px;}");
}

// this <--> table_view_
connect(table_view_, SIGNAL(direntClicked(const SeafDirent&)),
this, SLOT(onDirentClicked(const SeafDirent&)));
Expand Down Expand Up @@ -245,42 +229,6 @@ void FileBrowserDialog::init()
enterPath(current_path_);
}

void FileBrowserDialog::createTitleBar()
{
header_ = new QWidget;
header_->setObjectName("mHeader");
QHBoxLayout *layout = new QHBoxLayout;
layout->setContentsMargins(1, 1, 1, 1);
layout->setSpacing(0);
header_->setLayout(layout);

QSpacerItem *spacer1 = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
layout->addSpacerItem(spacer1);

brand_label_ = new QLabel(windowTitle());
brand_label_->setObjectName("mBrand");
layout->addWidget(brand_label_);

QSpacerItem *spacer2 = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
layout->addSpacerItem(spacer2);

minimize_button_ = new QPushButton;
minimize_button_->setObjectName("mMinimizeBtn");
minimize_button_->setToolTip(tr("Minimize"));
minimize_button_->setIcon(awesome->icon(icon_minus, QColor("#808081")));
layout->addWidget(minimize_button_);
connect(minimize_button_, SIGNAL(clicked()), this, SLOT(showMinimized()));

close_button_ = new QPushButton;
close_button_->setObjectName("mCloseBtn");
close_button_->setToolTip(tr("Close"));
close_button_->setIcon(awesome->icon(icon_remove, QColor("#808081")));
layout->addWidget(close_button_);
connect(close_button_, SIGNAL(clicked()), this, SLOT(close()));

header_->installEventFilter(this);
}

void FileBrowserDialog::createToolBar()
{
toolbar_ = new QToolBar;
Expand Down Expand Up @@ -1152,30 +1100,6 @@ void FileBrowserDialog::onCancelDownload(const SeafDirent& dirent)
::pathJoin(current_path_, dirent.name));
}

bool FileBrowserDialog::eventFilter(QObject *obj, QEvent *event)
{
if (obj == header_) {
if (event->type() == QEvent::MouseButtonPress) {
QMouseEvent *ev = (QMouseEvent *)event;
QRect frame_rect = frameGeometry();
old_pos_ = ev->globalPos() - frame_rect.topLeft();
return true;
} else if (event->type() == QEvent::MouseMove) {
QMouseEvent *ev = (QMouseEvent *)event;
move(ev->globalPos() - old_pos_);
return true;
}
}
return QDialog::eventFilter(obj, event);
}

void FileBrowserDialog::resizeEvent(QResizeEvent *event)
{
if (shouldUseFramelessWindow()) {
resizer_->move(rect().bottomRight() - resizer_->rect().bottomRight());
resizer_->raise();
}
}

void FileBrowserDialog::done(int retval)
{
Expand Down
7 changes: 0 additions & 7 deletions src/filebrowser/file-browser-dialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,10 @@ private slots:
private:
Q_DISABLE_COPY(FileBrowserDialog)

bool eventFilter(QObject *obj, QEvent *event);
void resizeEvent(QResizeEvent *event);
void done(int retval);
bool hasFilesToBePasted();
void setFilesToBePasted(bool is_copy, const QStringList &file_names);

void createTitleBar();
void createToolBar();
void createStatusBar();
void createFileTable();
Expand Down Expand Up @@ -162,15 +159,11 @@ private slots:
static Account account_to_be_pasted_from_;
static bool is_copyed_when_pasted_;

// title bar (windows and osx only)
QWidget *header_;
QLabel *brand_label_;
QPushButton *minimize_button_;
QPushButton *close_button_;
QPoint old_pos_;

QSizeGrip *resizer_;

// top toolbar
QToolBar *toolbar_;
QToolButton *backward_button_;
Expand Down

0 comments on commit 52a7acf

Please sign in to comment.