Skip to content
Merged
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 CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## v2.3.0

- [#5](https://github.com/procitec/qlitehtmlbrowser/issues/5): Implement selection


## v2.2.1

- [#17](https://github.com/procitec/qlitehtmlbrowser/issues/17): Scale changed signal
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.28)

project( QLiteHtmlBrowser VERSION 2.2.1 )
project( QLiteHtmlBrowser VERSION 2.3.0 )

include(GNUInstallDirs)

Expand Down
11 changes: 10 additions & 1 deletion include/qlitehtmlbrowser/QLiteHtmlBrowser.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ class QLITEHTMLBROWSER_EXPORT QLiteHtmlBrowser : public QWidget
{
Q_OBJECT

#ifdef UNIT_TEST
friend class FindTest;
friend class SelectionTest;
#endif

/// property to access the url that is currently shown in the browser
Q_PROPERTY( QUrl source READ source WRITE setSource )

Expand Down Expand Up @@ -155,6 +160,8 @@ class QLITEHTMLBROWSER_EXPORT QLiteHtmlBrowser : public QWidget
QColor highlightColor() const;
void setHighlightColor( QColor color );

QString selectedText() const;

public Q_SLOTS:
/// set URL to given url. The URL may be an url to local file, QtHelp, http etc.
/// The URL could contain an anchor element. Currently parameters to URL like
Expand Down Expand Up @@ -188,7 +195,9 @@ public Q_SLOTS:
/// send when scale changes
void scaleChanged();

/// send when selection changes
void selectionChanged();

protected:
private:
QLiteHtmlBrowserImpl* mImpl = nullptr;
};
2 changes: 2 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ target_sources(QLiteHtmlBrowser
QLiteHtmlBrowser.cpp
QLiteHtmlBrowserImpl.cpp
QLiteHtmlBrowserImpl.h
TextManager.h
TextManager.cpp
container_qt.cpp
container_qt.h
browserdefinitions.h
Expand Down
6 changes: 6 additions & 0 deletions src/QLiteHtmlBrowser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ QLiteHtmlBrowser::QLiteHtmlBrowser( QWidget* parent )
connect( mImpl, &QLiteHtmlBrowserImpl::urlChanged, this, &QLiteHtmlBrowser::sourceChanged );
connect( mImpl, &QLiteHtmlBrowserImpl::anchorClicked, this, &QLiteHtmlBrowser::anchorClicked );
connect( mImpl, &QLiteHtmlBrowserImpl::scaleChanged, this, &QLiteHtmlBrowser::scaleChanged );
connect( mImpl, &QLiteHtmlBrowserImpl::selectionChanged, this, &QLiteHtmlBrowser::selectionChanged );
}

QUrl QLiteHtmlBrowser::source() const
Expand Down Expand Up @@ -187,3 +188,8 @@ void QLiteHtmlBrowser::setHighlightColor( QColor color )
{
mImpl->setHighlightColor( color );
}

QString QLiteHtmlBrowser::selectedText() const
{
return mImpl->selectedText();
}
10 changes: 10 additions & 0 deletions src/QLiteHtmlBrowserImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ QLiteHtmlBrowserImpl::QLiteHtmlBrowserImpl( QWidget* parent )
shortcut = new QShortcut( QKeySequence{ QKeySequence::Back }, this );
connect( shortcut, &QShortcut::activated, this, &QLiteHtmlBrowserImpl::backward );
connect( mContainer, &container_qt::scaleChanged, this, &QLiteHtmlBrowserImpl::scaleChanged );
connect( mContainer, &container_qt::selectionChanged, this, &QLiteHtmlBrowserImpl::selectionChanged );

auto* layout = new QVBoxLayout;
layout->setContentsMargins( 0, 0, 0, 0 );
Expand Down Expand Up @@ -494,3 +495,12 @@ void QLiteHtmlBrowserImpl::previousFindMatch()
mContainer->findPreviousMatch();
}
}
QString QLiteHtmlBrowserImpl::selectedText() const
{
QString text;
if ( mContainer )
{
text = mContainer->selectedText();
}
return text;
}
7 changes: 7 additions & 0 deletions src/QLiteHtmlBrowserImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ class QLiteHtmlBrowserImpl : public QWidget
QColor highlightColor() const;
void setHighlightColor( QColor color );

QString selectedText() const;

protected:
void changeEvent( QEvent* ) override;
void mousePressEvent( QMouseEvent* ) override;
Expand All @@ -79,6 +81,11 @@ class QLiteHtmlBrowserImpl : public QWidget
void urlChanged( const QUrl& );
void anchorClicked( const QUrl& );
void scaleChanged();
void selectionChanged();

#ifdef UNIT_TEST
container_qt* container() const { return mContainer; }
#endif

private:
class HistoryEntry
Expand Down
Loading