HaikuDepot: Extracted MarkupTextView into its own files

This commit is contained in:
Stephan Aßmus
2014-10-26 23:37:17 +01:00
parent 7631f91496
commit f545fe6acc
6 changed files with 115 additions and 76 deletions
+3 -1
View File
@@ -39,12 +39,13 @@ Application HaikuDepot :
BitmapButton.cpp
BitmapView.cpp
DecisionProvider.cpp
FeaturedPackageView.cpp
FeaturedPackagesView.cpp
FilterView.cpp
JobStateListener.cpp
LinkView.cpp
main.cpp
MainWindow.cpp
MarkupTextView.cpp
MessagePackageListener.cpp
Model.cpp
PackageAction.cpp
@@ -78,6 +79,7 @@ DoCatalogs HaikuDepot :
x-vnd.Haiku-HaikuDepot
:
App.cpp
FeaturedPackagesView.cpp
FilterView.cpp
MainWindow.cpp
Model.cpp
@@ -3,7 +3,7 @@
* All rights reserved. Distributed under the terms of the MIT License.
*/
#include "FeaturedPackageView.h"
#include "FeaturedPackagesView.h"
#include <stdio.h>
@@ -22,7 +22,7 @@
#undef B_TRANSLATION_CONTEXT
#define B_TRANSLATION_CONTEXT "FeaturedPackageView"
#define B_TRANSLATION_CONTEXT "FeaturedPackagesView"
static const rgb_color kLightBlack = (rgb_color){ 60, 60, 60, 255 };
@@ -148,10 +148,10 @@ private:
};
// #pragma mark - FeaturedPackageView
// #pragma mark - FeaturedPackagesView
FeaturedPackageView::FeaturedPackageView()
FeaturedPackagesView::FeaturedPackagesView()
:
BView("featured package view", 0)
{
@@ -171,13 +171,13 @@ FeaturedPackageView::FeaturedPackageView()
}
FeaturedPackageView::~FeaturedPackageView()
FeaturedPackagesView::~FeaturedPackagesView()
{
}
void
FeaturedPackageView::AddPackage(const PackageInfoRef& package)
FeaturedPackagesView::AddPackage(const PackageInfoRef& package)
{
PackageView* view = new PackageView();
view->SetPackage(package);
@@ -186,7 +186,7 @@ FeaturedPackageView::AddPackage(const PackageInfoRef& package)
void
FeaturedPackageView::Clear()
FeaturedPackagesView::Clear()
{
for (int32 i = fPackageListLayout->CountItems() - 1;
BLayoutItem* item = fPackageListLayout->ItemAt(i); i--) {
@@ -2,8 +2,8 @@
* Copyright 2014, Stephan Aßmus <superstippi@gmx.de>.
* All rights reserved. Distributed under the terms of the MIT License.
*/
#ifndef FEATURED_PACKAGE_VIEW_H
#define FEATURED_PACKAGE_VIEW_H
#ifndef FEATURED_PACKAGES_VIEW_H
#define FEATURED_PACKAGES_VIEW_H
#include <View.h>
@@ -15,10 +15,10 @@
class BGroupLayout;
class FeaturedPackageView : public BView {
class FeaturedPackagesView : public BView {
public:
FeaturedPackageView();
virtual ~FeaturedPackageView();
FeaturedPackagesView();
virtual ~FeaturedPackagesView();
void AddPackage(const PackageInfoRef& package);
void Clear();
@@ -29,4 +29,4 @@ private:
};
#endif // FEATURED_PACKAGE_VIEW_H
#endif // FEATURED_PACKAGES_VIEW_H
+1 -62
View File
@@ -30,13 +30,12 @@
#include "BitmapButton.h"
#include "BitmapView.h"
#include "LinkView.h"
#include "MarkupParser.h"
#include "MarkupTextView.h"
#include "MessagePackageListener.h"
#include "PackageActionHandler.h"
#include "PackageManager.h"
#include "RatingView.h"
#include "ScrollableGroupView.h"
#include "TextDocumentView.h"
#include "TextView.h"
@@ -109,66 +108,6 @@ public:
};
class MarkupTextView : public TextDocumentView {
public:
MarkupTextView(const char* name)
:
TextDocumentView(name)
{
SetEditingEnabled(false);
CharacterStyle regularStyle;
float fontSize = regularStyle.Font().Size();
ParagraphStyle paragraphStyle;
paragraphStyle.SetJustify(true);
paragraphStyle.SetSpacingTop(ceilf(fontSize * 0.3f));
paragraphStyle.SetLineSpacing(ceilf(fontSize * 0.2f));
fMarkupParser.SetStyles(regularStyle, paragraphStyle);
}
void SetText(const BString& markupText)
{
SetTextDocument(fMarkupParser.CreateDocumentFromMarkup(markupText));
}
void SetText(const BString heading, const BString& markupText)
{
TextDocumentRef document(new(std::nothrow) TextDocument(), true);
Paragraph paragraph(fMarkupParser.HeadingParagraphStyle());
paragraph.Append(TextSpan(heading,
fMarkupParser.HeadingCharacterStyle()));
document->Append(paragraph);
fMarkupParser.AppendMarkup(document, markupText);
SetTextDocument(document);
}
void SetDisabledText(const BString& text)
{
TextDocumentRef document(new(std::nothrow) TextDocument(), true);
ParagraphStyle paragraphStyle;
paragraphStyle.SetAlignment(ALIGN_CENTER);
CharacterStyle disabledStyle(fMarkupParser.NormalCharacterStyle());
disabledStyle.SetForegroundColor(kLightBlack);
Paragraph paragraph(paragraphStyle);
paragraph.Append(TextSpan(text, disabledStyle));
document->Append(paragraph);
SetTextDocument(document);
}
private:
MarkupParser fMarkupParser;
};
// #pragma mark - rating stats
@@ -0,0 +1,70 @@
/*
* Copyright 2013-2014, Stephan Aßmus <superstippi@gmx.de>.
* All rights reserved. Distributed under the terms of the MIT License.
*/
#include "MarkupTextView.h"
static const rgb_color kLightBlack = (rgb_color){ 60, 60, 60, 255 };
MarkupTextView::MarkupTextView(const char* name)
:
TextDocumentView(name)
{
SetEditingEnabled(false);
CharacterStyle regularStyle;
float fontSize = regularStyle.Font().Size();
ParagraphStyle paragraphStyle;
paragraphStyle.SetJustify(true);
paragraphStyle.SetSpacingTop(ceilf(fontSize * 0.3f));
paragraphStyle.SetLineSpacing(ceilf(fontSize * 0.2f));
fMarkupParser.SetStyles(regularStyle, paragraphStyle);
}
void
MarkupTextView::SetText(const BString& markupText)
{
SetTextDocument(fMarkupParser.CreateDocumentFromMarkup(markupText));
}
void
MarkupTextView::SetText(const BString heading, const BString& markupText)
{
TextDocumentRef document(new(std::nothrow) TextDocument(), true);
Paragraph paragraph(fMarkupParser.HeadingParagraphStyle());
paragraph.Append(TextSpan(heading,
fMarkupParser.HeadingCharacterStyle()));
document->Append(paragraph);
fMarkupParser.AppendMarkup(document, markupText);
SetTextDocument(document);
}
void
MarkupTextView::SetDisabledText(const BString& text)
{
TextDocumentRef document(new(std::nothrow) TextDocument(), true);
ParagraphStyle paragraphStyle;
paragraphStyle.SetAlignment(ALIGN_CENTER);
CharacterStyle disabledStyle(fMarkupParser.NormalCharacterStyle());
disabledStyle.SetForegroundColor(kLightBlack);
Paragraph paragraph(paragraphStyle);
paragraph.Append(TextSpan(text, disabledStyle));
document->Append(paragraph);
SetTextDocument(document);
}
@@ -0,0 +1,28 @@
/*
* Copyright 2013-2014, Stephan Aßmus <superstippi@gmx.de>.
* All rights reserved. Distributed under the terms of the MIT License.
*/
#ifndef MARKUP_TEXT_VIEW_H
#define MARKUP_TEXT_VIEW_H
#include "MarkupParser.h"
#include "TextDocumentView.h"
class MarkupTextView : public TextDocumentView {
public:
MarkupTextView(const char* name);
void SetText(const BString& markupText);
void SetText(const BString heading,
const BString& markupText);
void SetDisabledText(const BString& text);
private:
MarkupParser fMarkupParser;
};
#endif // MARKUP_TEXT_VIEW_H