Skip to content

Commit

Permalink
Add style selection (#129)
Browse files Browse the repository at this point in the history
  • Loading branch information
variar committed Sep 24, 2020
1 parent 2cbf9bf commit c8f7c28
Show file tree
Hide file tree
Showing 15 changed files with 149 additions and 42 deletions.
1 change: 1 addition & 0 deletions src/app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ set(MAIN_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/messagereceiver.h
${CMAKE_CURRENT_SOURCE_DIR}/kloggapp.h
${CMAKE_CURRENT_SOURCE_DIR}/klogg.qrc
${CMAKE_CURRENT_SOURCE_DIR}/qdarkstyle/style.qrc
${DOCUMENTATION_RESOURCE}
${ICON_FILE})

Expand Down
2 changes: 1 addition & 1 deletion src/app/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ static void print_version()
std::cout << "Built " << kloggBuildDate().data() << " from " << kloggCommit().data() << "("
<< kloggGitVersion().data() << ")\n";

std::cout << "Copyright (C) 2019 Nicolas Bonnefon, Anton Filimonov and other contributors\n";
std::cout << "Copyright (C) 2020 Nicolas Bonnefon, Anton Filimonov and other contributors\n";
std::cout << "This is free software. You may redistribute copies of it under the terms of\n";
std::cout << "the GNU General Public License <http://www.gnu.org/licenses/gpl.html>.\n";
std::cout << "There is NO WARRANTY, to the extent permitted by law.\n";
Expand Down
1 change: 1 addition & 0 deletions src/ui/include/crawlerwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ class CrawlerWidget : public QSplitter,
void stopSearch();
// Instructs the widget to reconfigure itself because Config() has changed.
void applyConfiguration();
void loadIcons();
// QuickFind is being entered, save the focus for incremental qf.
void enteringQuickFind();
// QuickFind is being closed.
Expand Down
22 changes: 13 additions & 9 deletions src/ui/include/iconloader.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,25 @@

#include <QIcon>

class IconLoader
{
class QWidget;

class IconLoader {
public:
IconLoader() { }
virtual ~IconLoader() { }
QIcon load(QString name);
explicit IconLoader( QWidget* widget );
QIcon load( QString name );

private:
bool shouldInvert() const;
bool shouldAutoInvert(QString) const;
bool shouldAutoInvert( QString ) const;

QPixmap loadPixmap(QString, int) const;
QPixmap loadPixmap( QString, int ) const;

QPixmap invertPixmap(QPixmap) const;
QPixmap invertPixmap( QPixmap ) const;

QString makeNonScalableFilename(QString, int, bool) const;
QString makeNonScalableFilename( QString, int, bool ) const;

private:
QWidget* widget_;
};

#endif // KLOGG_ICONLOADER_H
1 change: 1 addition & 0 deletions src/ui/include/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ class MainWindow : public QMainWindow {

private:
void createActions();
void loadIcons();
void createMenus();
void createToolBars();
void createTrayIcon();
Expand Down
1 change: 1 addition & 0 deletions src/ui/include/optionsdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ class OptionsDialog : public QDialog, public Ui::OptionsDialog {
void setupSearchResultsCache();
void setupLogging();
void setupArchives();
void setupStyles();

int getRegexpIndex( SearchRegexpType syntax ) const;
SearchRegexpType getRegexpTypeFromIndex( int index ) const;
Expand Down
12 changes: 12 additions & 0 deletions src/ui/include/optionsdialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,18 @@
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="styleBox">
<property name="title">
<string>Style</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_15">
<item>
<widget class="QComboBox" name="styleComboBox"/>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="hidpiGroupBox">
<property name="title">
Expand Down
4 changes: 2 additions & 2 deletions src/ui/src/abstractlogview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1694,7 +1694,7 @@ void AbstractLogView::drawTextArea( QPaintDevice* paint_device )
painter.setPen( palette.color( QPalette::Text ) );
painter.fillRect( contentStartPosX - SEPARATOR_WIDTH, 0,
lineNumberAreaWidth + SEPARATOR_WIDTH, paintDeviceHeight,
palette.color( QPalette::AlternateBase ) );
palette.color( QPalette::Disabled, QPalette::Text ) );

painter.drawLine( contentStartPosX + lineNumberAreaWidth - SEPARATOR_WIDTH, 0,
contentStartPosX + lineNumberAreaWidth - SEPARATOR_WIDTH,
Expand All @@ -1705,7 +1705,7 @@ void AbstractLogView::drawTextArea( QPaintDevice* paint_device )
}
else {
painter.fillRect( contentStartPosX - SEPARATOR_WIDTH, 0, SEPARATOR_WIDTH + 1,
paintDeviceHeight, palette.color( QPalette::AlternateBase ) );
paintDeviceHeight, palette.color( QPalette::Disabled, QPalette::Text ) );
// contentStartPosX += SEPARATOR_WIDTH;
}

Expand Down
39 changes: 25 additions & 14 deletions src/ui/src/crawlerwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ class CrawlerWidgetContext : public ViewContextInterface {
// the data is attached.
CrawlerWidget::CrawlerWidget( QWidget* parent )
: QSplitter( parent )
, iconLoader_{ this }
{
}

Expand Down Expand Up @@ -364,8 +365,8 @@ void CrawlerWidget::clearSearchItems()

void CrawlerWidget::showSearchContextMenu()
{
if(searchLineContextMenu)
searchLineContextMenu->exec(QCursor::pos());
if ( searchLineContextMenu )
searchLineContextMenu->exec( QCursor::pos() );
}

// When receiving the 'newDataAvailable' signal from LogFilteredData
Expand Down Expand Up @@ -525,6 +526,9 @@ void CrawlerWidget::applyConfiguration()
filteredView->updateDisplaySize();
filteredView->update();

loadIcons();
searchInfoLineDefaultPalette = searchInfoLine->palette();

// Update the SearchLine (history)
updateSearchCombo();

Expand Down Expand Up @@ -662,7 +666,8 @@ void CrawlerWidget::searchRefreshChangedHandler( bool isRefreshing )

void CrawlerWidget::matchCaseChangedHandler( bool shouldMatchCase )
{
searchLineCompleter->setCaseSensitivity( shouldMatchCase ? Qt::CaseSensitive : Qt::CaseInsensitive );
searchLineCompleter->setCaseSensitivity( shouldMatchCase ? Qt::CaseSensitive
: Qt::CaseInsensitive );
}

void CrawlerWidget::searchTextChangeHandler( QString )
Expand Down Expand Up @@ -821,21 +826,18 @@ void CrawlerWidget::setup()

matchCaseButton = new QToolButton();
matchCaseButton->setToolTip( "Match case" );
matchCaseButton->setIcon( iconLoader_.load( "icons8-font-size" ) );
matchCaseButton->setCheckable( true );
matchCaseButton->setFocusPolicy( Qt::NoFocus );
matchCaseButton->setContentsMargins( 2, 2, 2, 2 );

useRegexpButton = new QToolButton();
useRegexpButton->setToolTip( "Use regex" );
useRegexpButton->setIcon( iconLoader_.load( "regex" ) );
useRegexpButton->setCheckable( true );
useRegexpButton->setFocusPolicy( Qt::NoFocus );
useRegexpButton->setContentsMargins( 2, 2, 2, 2 );

searchRefreshButton = new QToolButton();
searchRefreshButton->setToolTip( "Auto-refresh" );
searchRefreshButton->setIcon( iconLoader_.load( "icons8-search-refresh" ) );
searchRefreshButton->setCheckable( true );
searchRefreshButton->setFocusPolicy( Qt::NoFocus );
searchRefreshButton->setContentsMargins( 2, 2, 2, 2 );
Expand All @@ -851,22 +853,20 @@ void CrawlerWidget::setup()
searchLineEdit->lineEdit()->setMaxLength( std::numeric_limits<int>::max() / 1024 );
searchLineEdit->setContentsMargins( 2, 2, 2, 2 );

QAction *clearSearchItemsAction = new QAction( "Clear All Items", this );
QAction* clearSearchItemsAction = new QAction( "Clear All Items", this );
searchLineContextMenu = searchLineEdit->lineEdit()->createStandardContextMenu();
searchLineContextMenu->addSeparator();
searchLineContextMenu->addAction(clearSearchItemsAction);
searchLineEdit->setContextMenuPolicy(Qt::CustomContextMenu);
searchLineContextMenu->addAction( clearSearchItemsAction );
searchLineEdit->setContextMenuPolicy( Qt::CustomContextMenu );

setFocusProxy( searchLineEdit );

searchButton = new QToolButton();
searchButton->setIcon( iconLoader_.load( "icons8-search" ) );
searchButton->setText( tr( "Search" ) );
searchButton->setAutoRaise( true );
searchButton->setContentsMargins( 2, 2, 2, 2 );

stopButton = new QToolButton();
stopButton->setIcon( iconLoader_.load( "icons8-delete" ) );
stopButton->setAutoRaise( true );
stopButton->setEnabled( false );
stopButton->setVisible( false );
Expand Down Expand Up @@ -904,17 +904,19 @@ void CrawlerWidget::setup()
searchRefreshChangedHandler( searchRefreshButton->isChecked() );
matchCaseChangedHandler( matchCaseButton->isChecked() );


// Default splitter position (usually overridden by the config file)
setSizes( config.splitterSizes() );

loadIcons();

// Connect the signals
connect( searchLineEdit->lineEdit(), &QLineEdit::returnPressed, searchButton,
&QToolButton::click );
connect( searchLineEdit->lineEdit(), &QLineEdit::textEdited, this,
&CrawlerWidget::searchTextChangeHandler );

connect( searchLineEdit, &QWidget::customContextMenuRequested, this, &CrawlerWidget::showSearchContextMenu);
connect( searchLineEdit, &QWidget::customContextMenuRequested, this,
&CrawlerWidget::showSearchContextMenu );
connect( clearSearchItemsAction, &QAction::triggered, this, &CrawlerWidget::clearSearchItems );
connect( searchButton, &QToolButton::clicked, this, &CrawlerWidget::startNewSearch );
connect( stopButton, &QToolButton::clicked, this, &CrawlerWidget::stopSearch );
Expand Down Expand Up @@ -983,7 +985,7 @@ void CrawlerWidget::setup()
&CrawlerWidget::searchRefreshChangedHandler );

connect( matchCaseButton, &QPushButton::toggled, this,
&CrawlerWidget::matchCaseChangedHandler );
&CrawlerWidget::matchCaseChangedHandler );

// Advise the parent the checkboxes have been changed
// (for maintaining default config)
Expand All @@ -998,6 +1000,15 @@ void CrawlerWidget::setup()
QOverload<>::of( &LogMainView::setFocus ) );
}

void CrawlerWidget::loadIcons()
{
searchRefreshButton->setIcon( iconLoader_.load( "icons8-search-refresh" ) );
useRegexpButton->setIcon( iconLoader_.load( "regex" ) );
searchButton->setIcon( iconLoader_.load( "icons8-search" ) );
matchCaseButton->setIcon( iconLoader_.load( "icons8-font-size" ) );
stopButton->setIcon( iconLoader_.load( "icons8-delete" ) );
}

// Create a new search using the text passed, replace the currently
// used one and destroy the old one.
void CrawlerWidget::replaceCurrentSearch( const QString& searchText )
Expand Down
11 changes: 10 additions & 1 deletion src/ui/src/iconloader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,20 @@
#include <QPainter>
#include <QPalette>
#include <QPixmap>
#include <QStyleOption>
#include <QWidget>

#include "iconloader.h"

#include <array>

constexpr std::array<int, 8> IconSizes{ 0, 16 };

IconLoader::IconLoader( QWidget* widget )
: widget_{ widget }
{
}

QIcon IconLoader::load( QString name )
{
QIcon icon;
Expand All @@ -35,7 +42,9 @@ QIcon IconLoader::load( QString name )
}
bool IconLoader::shouldInvert() const
{
QColor bg = QApplication::palette().window().color();
QStyleOption style;
style.initFrom( widget_ );
auto bg = style.palette.window().color();
bool darkBackground = ( bg.red() + bg.green() + bg.blue() <= 384 );
return darkBackground;
}
Expand Down
Loading

0 comments on commit c8f7c28

Please sign in to comment.