Skip to content

Commit

Permalink
Created ui file for OutputDialog
Browse files Browse the repository at this point in the history
  • Loading branch information
flying-sheep committed May 13, 2017
1 parent 19eb70e commit 09ca420
Show file tree
Hide file tree
Showing 17 changed files with 417 additions and 228 deletions.
1 change: 0 additions & 1 deletion notifier/octopi-notifier/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,6 @@ void MainWindow::doSystemUpgrade()
m_actionSystemUpgrade->setEnabled(false);

OutputDialog *dlg = new OutputDialog(this);
dlg->setFrameShape(QFrame::NoFrame);

if (m_debugInfo)
dlg->setDebugMode(true);
Expand Down
9 changes: 8 additions & 1 deletion notifier/octopi-notifier/octopi-notifier.pro
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ OBJECTS_DIR += ../build-octopi-notifier
MOC_DIR += ../build-octopi-notifier
UI_DIR += ../build-octopi-notifier

# so that .ui files can find headers
# no matter where they’re included from
INCLUDEPATH += ../..

HEADERS += \
mainwindow.h \
outputdialog.h \
Expand Down Expand Up @@ -78,7 +82,10 @@ ALPM_BACKEND{
}

FORMS += ../../ui/transactiondialog.ui \
../../ui/optionsdialog.ui
../../ui/searchlineedit.ui \
../../ui/searchbar.ui \
../../ui/optionsdialog.ui \
ui/outputdialog.ui

RESOURCES += \
../../resources.qrc
Expand Down
79 changes: 27 additions & 52 deletions notifier/octopi-notifier/outputdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
*/

#include "outputdialog.h"
#include "ui_outputdialog.h"
#include "../../src/pacmanexec.h"
#include "../../src/searchbar.h"
#include "../../src/uihelper.h"
Expand All @@ -37,8 +38,11 @@
/*
* The obligatory constructor...
*/
OutputDialog::OutputDialog(QWidget *parent): QDialog(parent)
OutputDialog::OutputDialog(QWidget *parent):
QDialog(parent),
ui(new Ui::OutputDialog)
{
ui->setupUi(this);
init();
m_upgradeRunning = false;
m_debugInfo = false;
Expand All @@ -52,49 +56,20 @@ void OutputDialog::setDebugMode(bool newValue)
m_debugInfo = newValue;
}

QFrame::Shape OutputDialog::frameShape()
{
return m_textBrowser->frameShape();
}

void OutputDialog::setFrameShape(QFrame::Shape shape)
{
m_textBrowser->setFrameShape(shape);
}

/*
* Let's build the main widgets...
*/
void OutputDialog::init()
{
this->resize(650, 500);

setWindowTitle(QCoreApplication::translate("MainWindow", "System upgrade"));
setWindowIcon(IconHelper::getIconSystemUpgrade());
m_mainLayout = new QVBoxLayout(this);
m_textBrowser = new QTextBrowser(this);
m_progressBar = new QProgressBar(this);

m_textBrowser->setGeometry(QRect(0, 0, 650, 500));

m_mainLayout->addWidget(m_textBrowser);

m_searchBar = new SearchBar(this);
connect(m_searchBar, SIGNAL(textChanged(QString)), this, SLOT(onSearchBarTextChanged(QString)));
connect(m_searchBar, SIGNAL(closed()), this, SLOT(onSearchBarClosed()));
connect(m_searchBar, SIGNAL(findNext()), this, SLOT(onSearchBarFindNext()));
connect(m_searchBar, SIGNAL(findPrevious()), this, SLOT(onSearchBarFindPrevious()));
m_mainLayout->addWidget(m_progressBar);
m_mainLayout->addWidget(m_searchBar);
m_mainLayout->setSpacing(0);
m_mainLayout->setSizeConstraint(QLayout::SetMinimumSize);
m_mainLayout->setContentsMargins(2, 2, 2, 2);

m_progressBar->setMinimum(0);
m_progressBar->setMaximum(100);
m_progressBar->setValue(0);
m_progressBar->close();
m_searchBar->show();
connect(ui->m_searchBar, SIGNAL(textChanged(QString)), this, SLOT(onSearchBarTextChanged(QString)));
connect(ui->m_searchBar, SIGNAL(closed()), this, SLOT(onSearchBarClosed()));
connect(ui->m_searchBar, SIGNAL(findNext()), this, SLOT(onSearchBarFindNext()));
connect(ui->m_searchBar, SIGNAL(findPrevious()), this, SLOT(onSearchBarFindPrevious()));
ui->m_searchBar->show();

ui->m_progressBar->close();
}

/*
Expand Down Expand Up @@ -147,53 +122,53 @@ void OutputDialog::reject()
*/
void OutputDialog::onPencertange(int percentage)
{
if (percentage > 0 && !m_progressBar->isVisible()) m_progressBar->show();
m_progressBar->setValue(percentage);
if (percentage > 0 && !ui->m_progressBar->isVisible()) ui->m_progressBar->show();
ui->m_progressBar->setValue(percentage);
}

/*
* Helper method to position the text cursor always in the end of doc
*/
void OutputDialog::positionTextEditCursorAtEnd()
{
QTextCursor tc = m_textBrowser->textCursor();
QTextCursor tc = ui->m_textBrowser->textCursor();
tc.clearSelection();
tc.movePosition(QTextCursor::End);
m_textBrowser->setTextCursor(tc);
ui->m_textBrowser->setTextCursor(tc);
}

/*
* A helper method which writes the given string to the textbrowser
*/
void OutputDialog::writeToTabOutput(const QString &msg, TreatURLLinks treatURLLinks)
{
utils::writeToTextBrowser(m_textBrowser, msg, treatURLLinks);
utils::writeToTextBrowser(ui->m_textBrowser, msg, treatURLLinks);
}

/*
* Slot called whenever PacmanExec emits a new output
*/
void OutputDialog::onWriteOutput(const QString &output)
{
utils::positionTextEditCursorAtEnd(m_textBrowser);
m_textBrowser->insertHtml(output);
m_textBrowser->ensureCursorVisible();
utils::positionTextEditCursorAtEnd(ui->m_textBrowser);
ui->m_textBrowser->insertHtml(output);
ui->m_textBrowser->ensureCursorVisible();
}

/*
* Helper method to find the given "findText" in a TextEdit
*/
bool OutputDialog::textInTabOutput(const QString& findText)
{
return (utils::strInQTextEdit(m_textBrowser, findText));
return (utils::strInQTextEdit(ui->m_textBrowser, findText));
}

/*
* Slot called whenever PacmanExec finishes its job
*/
void OutputDialog::pacmanProcessFinished(int exitCode, QProcess::ExitStatus exitStatus)
{
m_progressBar->close();
ui->m_progressBar->close();

if ((exitCode == 0) && exitStatus == QProcess::NormalExit)
{
Expand Down Expand Up @@ -226,31 +201,31 @@ void OutputDialog::pacmanProcessFinished(int exitCode, QProcess::ExitStatus exit
*/
void OutputDialog::onSearchBarTextChanged(QString strToSearch)
{
utils::searchBarTextChangedInTextBrowser(m_textBrowser, m_searchBar, strToSearch);
utils::searchBarTextChangedInTextBrowser(ui->m_textBrowser, ui->m_searchBar, strToSearch);
}

/*
* User closed the search bar
*/
void OutputDialog::onSearchBarClosed()
{
utils::searchBarClosedInTextBrowser(m_textBrowser, m_searchBar);
utils::searchBarClosedInTextBrowser(ui->m_textBrowser, ui->m_searchBar);
}

/*
* User requested next found string
*/
void OutputDialog::onSearchBarFindNext()
{
utils::searchBarFindNextInTextBrowser(m_textBrowser, m_searchBar);
utils::searchBarFindNextInTextBrowser(ui->m_textBrowser, ui->m_searchBar);
}

/*
* User requested previous found string
*/
void OutputDialog::onSearchBarFindPrevious()
{
utils::searchBarFindPreviousInTextBrowser(m_textBrowser, m_searchBar);
utils::searchBarFindPreviousInTextBrowser(ui->m_textBrowser, ui->m_searchBar);
}

/*
Expand All @@ -277,7 +252,7 @@ void OutputDialog::keyPressEvent(QKeyEvent *ke)
{
if(ke->key() == Qt::Key_F && ke->modifiers() == Qt::ControlModifier)
{
m_searchBar->show();
ui->m_searchBar->show();
}
else if(ke->key() == Qt::Key_Escape)
{
Expand Down
12 changes: 5 additions & 7 deletions notifier/octopi-notifier/outputdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,16 @@ class QWidget;
class QCloseEvent;
class QKeyEvent;

namespace Ui {
class OutputDialog;
}

class OutputDialog : public QDialog
{
Q_OBJECT

Q_PROPERTY(QFrame::Shape frameShape READ frameShape WRITE setFrameShape USER true)

private:
QTextBrowser *m_textBrowser;
QProgressBar *m_progressBar;
QVBoxLayout *m_mainLayout;
Ui::OutputDialog *ui;
PacmanExec *m_pacmanExec;
SearchBar *m_searchBar;
bool m_upgradeRunning;
Expand Down Expand Up @@ -77,12 +77,10 @@ private slots:
public:
explicit OutputDialog(QWidget *parent = 0);
void setDebugMode(bool newValue);
QFrame::Shape frameShape();

public slots:
void show();
void reject();
void setFrameShape(QFrame::Shape shape);
};

#endif // OUTPUTDIALOG_H
74 changes: 74 additions & 0 deletions notifier/octopi-notifier/ui/outputdialog.ui
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>OutputDialog</class>
<widget class="QDialog" name="OutputDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>650</width>
<height>550</height>
</rect>
</property>
<property name="windowTitle">
<string>System upgrade</string>
</property>
<property name="windowIcon">
<iconset theme="go-up">
<normaloff>.</normaloff>.</iconset>
</property>
<layout class="QVBoxLayout" name="m_mainLayout">
<property name="spacing">
<number>0</number>
</property>
<property name="sizeConstraint">
<enum>QLayout::SetMinimumSize</enum>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QTextBrowser" name="m_textBrowser">
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
</widget>
</item>
<item>
<widget class="QProgressBar" name="m_progressBar">
<property name="minimum">
<number>0</number>
</property>
<property name="maximum">
<number>100</number>
</property>
<property name="value">
<number>0</number>
</property>
</widget>
</item>
<item>
<widget class="SearchBar" name="m_searchBar" native="true"/>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>SearchBar</class>
<extends>QWidget</extends>
<header>src/searchbar.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>
8 changes: 5 additions & 3 deletions octopi.pro
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ HEADERS += src/QtSolutions/qtsingleapplication.h \
src/terminal.h \
src/pacmanexec.h \
src/constants.h \
src/optionsdialog.h
src/optionsdialog.h

ALPM_BACKEND{
HEADERS += src/alpmbackend.h
Expand Down Expand Up @@ -83,7 +83,7 @@ SOURCES += src/QtSolutions/qtsingleapplication.cpp \
src/utils.cpp \
src/terminal.cpp \
src/pacmanexec.cpp \
src/optionsdialog.cpp
src/optionsdialog.cpp

ALPM_BACKEND{
SOURCES += src/alpmbackend.cpp
Expand All @@ -92,7 +92,9 @@ ALPM_BACKEND{
FORMS += ui/mainwindow.ui \
ui/transactiondialog.ui \
ui/multiselectiondialog.ui \
ui/optionsdialog.ui
ui/optionsdialog.ui \
ui/searchbar.ui \
ui/searchlineedit.ui

RESOURCES += resources.qrc

Expand Down
1 change: 1 addition & 0 deletions src/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,7 @@ private slots:
void clearTransactionTreeView();
void positionInPkgListSearchByFile();
void positionInFirstMatch();
void searchBarShow();
void searchBarTextChangedInTextBrowser(const QString textToSearch);
void searchBarFindNextInTextBrowser();
void searchBarFindPreviousInTextBrowser();
Expand Down
2 changes: 2 additions & 0 deletions src/mainwindow_init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -738,6 +738,8 @@ void MainWindow::initActions()
actionGroup->setExclusive(true);
connect(actionGroup, SIGNAL(triggered(QAction*)), this, SLOT(tvPackagesSearchColumnChanged(QAction*)));

connect(ui->actionSearchInOutput, SIGNAL(triggered(bool)), this, SLOT(searchBarShow()));

ui->actionInstallLocalPackage->setIcon(IconHelper::getIconFolder());
ui->actionOpenDirectory->setIcon(IconHelper::getIconFolder());

Expand Down
Loading

0 comments on commit 09ca420

Please sign in to comment.