Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ project(QSkinny
HOMEPAGE_URL "https://github.com/uwerat/qskinny"
VERSION 0.8.0)

if(MSVC)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • move/remove before merging

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP")
message(STATUS "Added parallel build arguments to CMAKE_CXX_FLAGS: ${CMAKE_CXX_FLAGS}")
endif()

qsk_setup_options()

include(GNUInstallDirs)
Expand Down
4 changes: 3 additions & 1 deletion examples/listbox/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@
# SPDX-License-Identifier: BSD-3-Clause
############################################################################

qsk_add_example(listbox main.cpp)
qsk_add_example(listbox main.cpp
ListBox.h ListBox.cpp
TreeBox.h TreeBox.cpp)
44 changes: 44 additions & 0 deletions examples/listbox/ListBox.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/******************************************************************************
* QSkinny - Copyright (C) 2016 Uwe Rathmann
* SPDX-License-Identifier: BSD-3-Clause
*****************************************************************************/

#include "ListBox.h"
#include <QskFunctions.h>

ListBox::ListBox( QQuickItem* parent )
: Inherited( parent )
{
setAlternatingRowColors( true );

// increasing the padding of each row: usually the job of the skin !
setPaddingHint( Cell, QMargins( 10, 20, 10, 20 ) );

populate();

setSelectedRow( 5 );
}

void ListBox::populate()
{
const int count = 10000;

const QString format( "Row %1: The quick brown fox jumps over the lazy dog" );

QStringList entries;
entries.reserve( count );

for ( int i = 0; i < count; i++ )
{
entries += format.arg( i + 1 );
}

// we know, that the last entry is the longest one and
// can prevent the list box from having to find it out
// the expensive way.

const qreal maxWidth = qskHorizontalAdvance( effectiveFont( Cell ), entries.last() );
setColumnWidthHint( 0, maxWidth );

append( entries );
}
17 changes: 17 additions & 0 deletions examples/listbox/ListBox.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/******************************************************************************
* QSkinny - Copyright (C) 2016 Uwe Rathmann
* SPDX-License-Identifier: BSD-3-Clause
*****************************************************************************/

#include <QskSimpleListBox.h>

class ListBox : public QskSimpleListBox
{
using Inherited = QskSimpleListBox;

public:
explicit ListBox( QQuickItem* parent = nullptr );

private:
void populate();
};
74 changes: 74 additions & 0 deletions examples/listbox/TreeBox.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/******************************************************************************
* QSkinny - Copyright (C) 2016 Uwe Rathmann
* SPDX-License-Identifier: BSD-3-Clause
*****************************************************************************/

#include "TreeBox.h"

QSK_SUBCONTROL( TreeBox, FirstRow )
QSK_SUBCONTROL( TreeBox, SecondRow )

TreeBox::TreeBox( QQuickItem* const parent )
: Inherited( parent )
{
setAlternatingRowColors( true );
setPaddingHint( Cell, QMargins( 10, 20, 10, 20 ) );

setAlternatingRowColors( true );
setColor( FirstRow, Qt::white );
setColor( SecondRow, color( Panel ) );
updateScrollableSize();
};

QskAspect::Subcontrol TreeBox::rowSubControl( int row ) const noexcept
{
if ( alternatingRowColors() )
{
if ( row == selectedRow() )
{
return Cell;
}
return row % 2 == 0 ? Cell : QskAspect::NoSubcontrol;
}
return QskAspect::NoSubcontrol;
}

int TreeBox::rowCount() const
{
return 100000;
}

int TreeBox::columnCount() const
{
return 2;
}

qreal TreeBox::columnWidth( int col ) const
{
return col == 0 ? 100 : 350;
}

qreal TreeBox::rowHeight() const
{
const auto hint = strutSizeHint( Cell );
const auto padding = paddingHint( Cell );

qreal h = effectiveFontHeight( Text );
h += padding.top() + padding.bottom();

return qMax( h, hint.height() );
}

Q_INVOKABLE QVariant TreeBox::valueAt( int row, int col ) const
{
if ( col == 0 )
{
return QString::number( row );
}
return QStringLiteral( "The quick brown fox jumps over the lazy dog" );
}

qreal TreeBox::rowOffset( int row ) const
{
return ( row % 4 ) * 10;

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In a real scenerio the user must provide usefull offsets for a valid tree structure

}
25 changes: 25 additions & 0 deletions examples/listbox/TreeBox.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/******************************************************************************
* QSkinny - Copyright (C) 2016 Uwe Rathmann
* SPDX-License-Identifier: BSD-3-Clause
*****************************************************************************/

#pragma once

#include <QskTreeView.h>

class TreeBox final : public QskTreeView
{
using Inherited = QskTreeView;

public:
QSK_SUBCONTROLS( FirstRow, SecondRow )

explicit TreeBox( QQuickItem* parent = nullptr );
QskAspect::Subcontrol rowSubControl( int row ) const noexcept override;
int rowCount() const override;
int columnCount() const override;
qreal columnWidth( int col ) const override;
qreal rowHeight() const override;
Q_INVOKABLE QVariant valueAt( int row, int col ) const override;
qreal rowOffset( int row ) const override;
};
57 changes: 11 additions & 46 deletions examples/listbox/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,56 +5,16 @@

#include <SkinnyShortcut.h>

#include <QskAspect.h>
#ifdef ITEM_STATISTICS
#include <QskObjectCounter.h>
#include <QskSimpleListBox.h>
#endif
#include <QskLinearBox.h>
#include <QskWindow.h>
#include <QskFunctions.h>

#include <QFontMetricsF>
#include <QGuiApplication>

class ListBox : public QskSimpleListBox
{
public:
ListBox()
{
setMargins( QMarginsF( 15, 10, 10, 10 ) );
setAlternatingRowColors( true );

// increasing the padding of each row: usually the job of the skin !
setPaddingHint( Cell, QMargins( 10, 20, 10, 20 ) );

populate();

setSelectedRow( 5 );
}

private:
void populate()
{
const int count = 10000;

const QString format( "Row %1: The quick brown fox jumps over the lazy dog" );

QStringList entries;
entries.reserve( count );

for ( int i = 0; i < count; i++ )
{
entries += format.arg( i + 1 );
}

// we know, that the last entry is the longest one and
// can prevent the list box from having to find it out
// the expensive way.

const qreal maxWidth = qskHorizontalAdvance( effectiveFont( Cell ), entries.last() );
setColumnWidthHint( 0, maxWidth );

append( entries );
}
};
#include "ListBox.h"
#include "TreeBox.h"

int main( int argc, char* argv[] )
{
Expand All @@ -69,7 +29,12 @@ int main( int argc, char* argv[] )
QskWindow window;
window.setColor( "Silver" );

window.addItem( new ListBox() );
auto* const layout = new QskLinearBox( Qt::Horizontal );
layout->setSpacing( 8 );
( void ) new ListBox( layout );
( void ) new TreeBox( layout );

window.addItem( layout );
window.resize( 400, 600 );
window.show();

Expand Down
18 changes: 17 additions & 1 deletion skins/material3/QskMaterial3Skin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <QskGraphicIO.h>
#include <QskInputPanelBox.h>
#include <QskListView.h>
#include <QskTreeView.h>
#include <QskMenu.h>
#include <QskPageIndicator.h>
#include <QskPushButton.h>
Expand Down Expand Up @@ -88,6 +89,7 @@ namespace
void setupInputPanel();
void setupVirtualKeyboard();
void setupListView();
void setupTreeView();
void setupMenu();
void setupPageIndicator();
void setupPopup();
Expand Down Expand Up @@ -154,6 +156,7 @@ void Editor::setup()
setupInputPanel();
setupVirtualKeyboard();
setupListView();
setupTreeView();
setupMenu();
setupPageIndicator();
setupPopup();
Expand Down Expand Up @@ -1160,7 +1163,20 @@ void Editor::setupListView()
using Q = QskListView;

setPadding( Q::Cell, { 16_dp, 12_dp, 16_dp, 12_dp } );
setBoxBorderMetrics( Q::Cell, { 0, 0, 0, 1_dp } );
setBoxBorderMetrics( Q::Cell, { 0, 1_dp, 0, 1_dp } );
setBoxBorderColors( Q::Cell, m_pal.outline );
setColor( Q::Cell, m_pal.surface );
setColor( Q::Cell | Q::Selected, m_pal.primary12 );

setColor( Q::Text, m_pal.onSurfaceVariant );
}

void Editor::setupTreeView()
{
using Q = QskTreeView;

setPadding( Q::Cell, { 16_dp, 12_dp, 16_dp, 12_dp } );
setBoxBorderMetrics( Q::Cell, { 0, 1_dp, 0, 1_dp } );
setBoxBorderColors( Q::Cell, m_pal.outline );
setColor( Q::Cell, m_pal.surface );
setColor( Q::Cell | Q::Selected, m_pal.primary12 );
Expand Down
17 changes: 17 additions & 0 deletions skins/squiek/QskSquiekSkin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <QskInputPanelBox.h>
#include <QskInputPredictionBar.h>
#include <QskListView.h>
#include <QskTreeView.h>
#include <QskMenu.h>
#include <QskPageIndicator.h>
#include <QskPopup.h>
Expand Down Expand Up @@ -156,6 +157,7 @@ namespace
void setupInputPredictionBar();
void setupVirtualKeyboard();
void setupListView();
void setupTreeView();
void setupMenu();
void setupPageIndicator();
void setupPopup();
Expand Down Expand Up @@ -280,6 +282,7 @@ void Editor::setup()
setupInputPredictionBar();
setupVirtualKeyboard();
setupListView();
setupTreeView();
setupMenu();
setupPageIndicator();
setupPopup();
Expand Down Expand Up @@ -1043,6 +1046,20 @@ void Editor::setupListView()
setColor( Q::Text | Q::Selected, m_pal.highlightedText );
}

void Editor::setupTreeView()
{
using Q = QskTreeView;

// padding for each cell
setPadding( Q::Cell, QskMargins( 4, 8 ) );

setColor( Q::Text, m_pal.themeForeground );
setColor( Q::Cell, m_pal.contrasted );

setColor( Q::Cell | Q::Selected, m_pal.highlighted );
setColor( Q::Text | Q::Selected, m_pal.highlightedText );
}

void Editor::setupSubWindow()
{
using A = QskAspect;
Expand Down
4 changes: 4 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,8 @@ list(APPEND HEADERS
controls/QskInputGrabber.h
controls/QskListView.h
controls/QskListViewSkinlet.h
controls/QskTreeView.h
controls/QskTreeViewSkinlet.h
controls/QskMenu.h
controls/QskMenuSkinlet.h
controls/QskObjectTree.h
Expand Down Expand Up @@ -278,6 +280,8 @@ list(APPEND SOURCES
controls/QskInputGrabber.cpp
controls/QskListView.cpp
controls/QskListViewSkinlet.cpp
controls/QskTreeView.cpp
controls/QskTreeViewSkinlet.cpp
controls/QskMenuSkinlet.cpp
controls/QskMenu.cpp
controls/QskObjectTree.cpp
Expand Down
Loading