Skip to content

Commit

Permalink
Use native window for sync errors dialog.
Browse files Browse the repository at this point in the history
  • Loading branch information
lins05 committed May 2, 2017
1 parent 52a7acf commit 1f4c32c
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 110 deletions.
30 changes: 0 additions & 30 deletions qt.css
Original file line number Diff line number Diff line change
Expand Up @@ -606,36 +606,6 @@ SyncErrorsDialog {
min-height: 300px;
}

SyncErrorsDialog QSizeGrip {
margin-right: 2px;
}

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

SyncErrorsDialog QWidget#mHeader {
min-height: 25px;
max-height: 40px;
margin-left: 10px;
margin-right: 10px;
padding-top: 5px;
padding-bottom: 5px;
text-align: center;
}

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

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


SyncErrorsTableView {
border: 0;
margin: 0;
Expand Down
80 changes: 7 additions & 73 deletions src/ui/sync-errors-dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,15 @@ SyncErrorsDialog::SyncErrorsDialog(QWidget *parent)

setWindowTitle(tr("File Sync Errors"));
setWindowIcon(QIcon(":/images/seafile.png"));
setWindowFlags((windowFlags() & ~Qt::WindowContextHelpButtonHint & ~Qt::Dialog)
#if !defined(Q_OS_MAC)
| Qt::FramelessWindowHint
#endif
| Qt::Window);

resizer_ = new QSizeGrip(this);
resizer_->resize(resizer_->sizeHint());
setAttribute(Qt::WA_TranslucentBackground, true);
Qt::WindowFlags flags =
(windowFlags() & ~Qt::WindowContextHelpButtonHint & ~Qt::Dialog) |
Qt::Window | Qt::WindowSystemMenuHint | Qt::CustomizeWindowHint |
Qt::WindowMinimizeButtonHint | Qt::WindowCloseButtonHint |
Qt::WindowMaximizeButtonHint;

setWindowFlags(flags);

createTitleBar();
createEmptyView();

table_ = new SyncErrorsTableView;
Expand All @@ -90,82 +88,18 @@ SyncErrorsDialog::SyncErrorsDialog(QWidget *parent)
stack_->insertWidget(INDEX_TABE_VIEW, table_);
stack_->setContentsMargins(0, 0, 0, 0);

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

#ifdef Q_OS_MAC
header_->setVisible(false);
#endif

onModelReset();
connect(model_, SIGNAL(modelReset()), this, SLOT(onModelReset()));
}

void SyncErrorsDialog::createTitleBar()
{
header_ = new QWidget;
header_->setObjectName("mHeader");
QHBoxLayout *layout = new QHBoxLayout;
layout->setContentsMargins(1, 1, 1, 4);
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);
}

bool SyncErrorsDialog::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 SyncErrorsDialog::closeEvent(QCloseEvent *event)
{
event->ignore();
this->hide();
}

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

void SyncErrorsDialog::updateErrors()
{
model_->updateErrors();
Expand Down
7 changes: 0 additions & 7 deletions src/ui/sync-errors-dialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

class QTimer;
class QStackedWidget;
class QResizeEvent;
class QSizeGrip;
class QLabel;
class QEvent;
Expand All @@ -29,20 +28,14 @@ class SyncErrorsDialog : public QDialog
SyncErrorsDialog(QWidget *parent=0);
void updateErrors();

void resizeEvent(QResizeEvent *event);
void closeEvent(QCloseEvent *event);

private slots:
void onModelReset();

private:
void createTitleBar();
void createEmptyView();

bool eventFilter(QObject *obj, QEvent *event);

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

0 comments on commit 1f4c32c

Please sign in to comment.