Skip to content

Commit

Permalink
Remove set minimumsize for messageBox - it kills HBox?
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergey Dryabzhinsky committed Jul 31, 2017
1 parent 071f6e7 commit 05a2f38
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 31 deletions.
66 changes: 35 additions & 31 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ MainWindow::MainWindow() : QMainWindow()
connect(handler, SIGNAL(sigINT()), SLOT(unixSignalQuit()));
connect(handler, SIGNAL(sigHUP()), SLOT(unixSignalHup()));

network_interface = new QNetworkInterface();

delayedResize = new QTimer();
delayedLoad = new QTimer();

Expand Down Expand Up @@ -166,8 +168,11 @@ void MainWindow::init(AnyOption *opts)
// --- Web View --- //
view = new WebView(this);

QPalette palette = this->palette();
palette.setColor(QPalette::Window, QColor(230,230,230,127));
QPalette paletteG = this->palette();
paletteG.setColor(QPalette::Window, QColor(220,240,220,127));

QPalette paletteR = this->palette();
paletteR.setColor(QPalette::Window, QColor(240,220,220,127));

topBox = new QHBoxLayout(view);
topBox->setContentsMargins(2, 2, 2, 2);
Expand All @@ -179,7 +184,7 @@ void MainWindow::init(AnyOption *opts)
loadProgress->setMinimumSize(100, 16);
loadProgress->setMaximumSize(100, 16);
loadProgress->setAutoFillBackground(true);
loadProgress->setPalette(palette);
loadProgress->setPalette(paletteG);

// Do not work... Need Layout...
loadProgress->setAlignment(Qt::AlignTop | Qt::AlignLeft);
Expand All @@ -194,17 +199,17 @@ void MainWindow::init(AnyOption *opts)
// --- Messages Box --- //
messagesBox = new QLabel();
messagesBox->setContentsMargins(2, 2, 2, 2);
messagesBox->setWordWrap(true);
// messagesBox->setWordWrap(true);
messagesBox->setAutoFillBackground(true);
messagesBox->setPalette(palette);
messagesBox->setPalette(paletteR);

// Do not work... Need Layout...
messagesBox->setAlignment(Qt::AlignTop | Qt::AlignJustify);
messagesBox->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
messagesBox->setAlignment(Qt::AlignVCenter);
messagesBox->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::MinimumExpanding);

messagesBox->hide();

topBox->addStretch(1);
topBox->addStretch(2);
topBox->addWidget(messagesBox, 1, Qt::AlignTop | Qt::AlignLeft);
}

Expand Down Expand Up @@ -343,9 +348,6 @@ void MainWindow::delayedWindowResize()
}
QApplication::processEvents(); //process events to force update

quint16 msgWidth = view->width() - loadProgress->width() - 16;
messagesBox->setMinimumWidth(msgWidth);

this->setFocusPolicy(Qt::StrongFocus);
this->focusWidget();

Expand All @@ -355,6 +357,12 @@ void MainWindow::delayedWindowResize()
QApplication::processEvents(); //process events to force update
}

void MainWindow::resizeEvent(QResizeEvent* event)
{
QMainWindow::resizeEvent(event);
// Your code here.
}

void MainWindow::delayedPageLoad()
{
// Wait 1 second. May be not here?
Expand Down Expand Up @@ -506,27 +514,31 @@ void MainWindow::keyPressEvent(QKeyEvent *event)
void MainWindow::handleQwkNetworkError(QNetworkReply::NetworkError error, QString message)
{
qDebug() << QDateTime::currentDateTime().toString()
<< "MainWindow::handleQwkError"
<< "MainWindow::handleQwkNetworkError"
;
if (message.contains("Host ") && message.contains(" not found")) {
// Don't give a damn
qDebug() << "Don't give a damn";
return;
}
/* if (message.contains("Error downloading ") && message.contains("server replied: Not Found")) {
// Don't give a damn
qDebug() << "Don't give a damn";
return;
}*/

// Unknown error if eth0 if up but cable out
if (error == QNetworkReply::UnknownNetworkError) {
if (message.contains("Network access is disabled")) {
// Check all interfaces if them has link up

bool hasLinkUp = false;
QNetworkInterface *network_interface = new QNetworkInterface();
foreach (QNetworkInterface interface, network_interface->allInterfaces()) {
if ((interface.flags() & QNetworkInterface::IsUp) &&
(interface.flags() & QNetworkInterface::IsRunning)
)
hasLinkUp = true;
}
delete network_interface;

if (hasLinkUp && view->page()->networkAccessManager()->networkAccessible() != QNetworkAccessManager::Accessible) {

Expand All @@ -544,11 +556,11 @@ void MainWindow::handleQwkNetworkError(QNetworkReply::NetworkError error, QStrin

qint32 delay_reload = qwkSettings->getInt("browser/network_error_reload_delay", 15000);

qDebug() << QDateTime::currentDateTime().toString()
<< "MainWindow::networkStateChanged -"
<< "Delay WebView reload by" << delay_reload << "msec."
;
if (delay_reload >= 0) {
qDebug() << QDateTime::currentDateTime().toString()
<< "MainWindow::networkStateChanged -"
<< "Delay WebView reload by" << delay_reload/1000. << "sec."
;
message += QString("\nPage reload queued! Plase wait ") + QVariant(delay_reload / 1000.).toString() + QString(" seconds...");
// Try reload broken view downloads
delayedLoad->singleShot(
Expand Down Expand Up @@ -581,12 +593,6 @@ void MainWindow::desktopResized(int p)
} else if (qwkSettings->getBool("view/fixed-size")) {
centerFixedSizeWindow();
}

QApplication::processEvents(); //process events to force update

quint16 msgWidth = view->width() - loadProgress->width() - 16;
messagesBox->setMinimumWidth(msgWidth);
messagesBox->setMaximumWidth(view->width());
}

/**
Expand Down Expand Up @@ -1055,15 +1061,13 @@ void MainWindow::networkStateChanged(QNetworkSession::State state)
if (doReload) {

bool hasLoFace = false;
QNetworkInterface *network_interface = new QNetworkInterface();
foreach (QNetworkInterface interface, network_interface->allInterfaces()) {
if ((interface.flags() & QNetworkInterface::IsUp) &&
(interface.flags() & QNetworkInterface::IsRunning) &&
(interface.flags() & QNetworkInterface::IsLoopBack)
)
hasLoFace = true;
}
delete network_interface;

if (hasLoFace && view->page()->networkAccessManager()->networkAccessible() != QNetworkAccessManager::Accessible) {

Expand All @@ -1082,12 +1086,12 @@ void MainWindow::networkStateChanged(QNetworkSession::State state)

qint32 delay_reload = qwkSettings->getInt("browser/network_error_reload_delay", 15000);

qDebug() << QDateTime::currentDateTime().toString()
<< "MainWindow::networkStateChanged -"
<< "Delay WebView reload by" << delay_reload << "msec."
;

if (delay_reload >= 0) {
qDebug() << QDateTime::currentDateTime().toString()
<< "MainWindow::networkStateChanged -"
<< "Delay WebView reload by" << delay_reload/1000. << "msec."
;

errStr += QString("\nPage reload queued! Plase wait ") + QVariant(delay_reload / 1000.).toString() + QString(" seconds...");
delayedLoad->singleShot(delay_reload, this, SLOT(delayedPageReload()));
}
Expand Down
2 changes: 2 additions & 0 deletions src/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ protected slots:
bool hideScrollbars();
bool disableSelection();
void keyPressEvent(QKeyEvent *event);
void resizeEvent(QResizeEvent* event);

private:
WebView *view; // Webkit Page View
Expand Down Expand Up @@ -141,6 +142,7 @@ protected slots:
bool isUrlRealyChanged;

QNetworkSession *n_session;
QNetworkInterface *network_interface;

QTimer *delayedResize;
QTimer *delayedLoad;
Expand Down

0 comments on commit 05a2f38

Please sign in to comment.