[haiku-commits] haiku: hrev45649 - src/kits/shared headers/private/shared

  • From: pulkomandy@xxxxxxxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Thu, 9 May 2013 21:32:20 +0200 (CEST)

hrev45649 adds 1 changeset to branch 'master'
old head: 01c5671de87bbecdcbcb06ab88ce1b240a78a58d
new head: 2b67ff24207110739a9c52e1a659775bfb8be432
overview: http://cgit.haiku-os.org/haiku/log/?qt=range&q=2b67ff2+%5E01c5671

----------------------------------------------------------------------------

2b67ff2: Add AddText method to AboutWindow
  
   * Factor out the code to add some data to the about window, with a header 
and a content under it
   * Make this method public so it's possible to add custom entries in an about 
box
   * If the method is called with only the header or only the content, the text 
is added non-bold and non-indented (like the description entry*).
   * Make the header text bold. I'm not sure it looks that good, after all. 
Thoughts ?

                                 [ Adrien Destugues <pulkomandy@xxxxxxxxx> ]

----------------------------------------------------------------------------

Revision:    hrev45649
Commit:      2b67ff24207110739a9c52e1a659775bfb8be432
URL:         http://cgit.haiku-os.org/haiku/commit/?id=2b67ff2
Author:      Adrien Destugues <pulkomandy@xxxxxxxxx>
Date:        Thu May  9 19:27:43 2013 UTC

----------------------------------------------------------------------------

2 files changed, 41 insertions(+), 38 deletions(-)
headers/private/shared/AboutWindow.h |  3 ++
src/kits/shared/AboutWindow.cpp      | 76 ++++++++++++++++----------------

----------------------------------------------------------------------------

diff --git a/headers/private/shared/AboutWindow.h 
b/headers/private/shared/AboutWindow.h
index a8ec0b5..9a3cc60 100644
--- a/headers/private/shared/AboutWindow.h
+++ b/headers/private/shared/AboutWindow.h
@@ -37,6 +37,9 @@ class BAboutWindow : public BWindow {
                        void                    AddVersionHistory(const char** 
history);
                        void                    AddExtraInfo(const char* 
extraInfo);
 
+                       void                    AddText(const char* header,
+                                                               const char** 
contents = NULL);
+
                        BBitmap*                Icon();
                        void                    SetIcon(BBitmap* icon);
 
diff --git a/src/kits/shared/AboutWindow.cpp b/src/kits/shared/AboutWindow.cpp
index 0b81b02..2d66bfc 100644
--- a/src/kits/shared/AboutWindow.cpp
+++ b/src/kits/shared/AboutWindow.cpp
@@ -176,6 +176,7 @@ AboutView::AboutView(const char* appName, const char* 
signature)
        fInfoView->SetInsets(5.0, 5.0, 5.0, 5.0);
        fInfoView->SetViewColor(ui_color(B_DOCUMENT_BACKGROUND_COLOR));
        fInfoView->SetHighColor(ui_color(B_DOCUMENT_TEXT_COLOR));
+       fInfoView->SetStylable(true);
 
        BScrollView* infoViewScroller = new BScrollView(
                "infoViewScroller", fInfoView, B_WILL_DRAW | B_FRAME_EVENTS,
@@ -435,16 +436,7 @@ BAboutWindow::AddDescription(const char* description)
        if (description == NULL)
                return;
 
-       const char* appDesc = B_TRANSLATE_MARK(description);
-       appDesc = gSystemCatalog.GetString(appDesc, "AboutWindow");
-
-       BString desc("");
-       if (fAboutView->InfoView()->TextLength() > 0)
-               desc << "\n\n";
-
-       desc << appDesc;
-
-       fAboutView->InfoView()->Insert(desc.String());
+       AddText(description);
 }
 
 
@@ -501,16 +493,7 @@ BAboutWindow::AddAuthors(const char** authors)
        const char* writtenBy = B_TRANSLATE_MARK("Written by:");
        writtenBy = gSystemCatalog.GetString(writtenBy, "AboutWindow");
 
-       BString text("");
-       if (fAboutView->InfoView()->TextLength() > 0)
-               text << "\n\n";
-
-       text << writtenBy;
-       text << "\n";
-       for (int32 i = 0; authors[i]; i++)
-               text << "    " << authors[i] << "\n";
-
-       fAboutView->InfoView()->Insert(text.String());
+       AddText(writtenBy, authors);
 }
 
 
@@ -523,15 +506,7 @@ BAboutWindow::AddSpecialThanks(const char** thanks)
        const char* specialThanks = B_TRANSLATE_MARK("Special Thanks:");
        specialThanks = gSystemCatalog.GetString(specialThanks, "AboutWindow");
 
-       BString text("");
-       if (fAboutView->InfoView()->TextLength() > 0)
-               text << "\n\n";
-
-       text << specialThanks << "\n";
-       for (int32 i = 0; thanks[i]; i++)
-               text << "    " << thanks[i] << "\n";
-
-       fAboutView->InfoView()->Insert(text.String());
+       AddText(specialThanks, thanks);
 }
 
 
@@ -544,15 +519,7 @@ BAboutWindow::AddVersionHistory(const char** history)
        const char* versionHistory = B_TRANSLATE_MARK("Version history:");
        versionHistory = gSystemCatalog.GetString(versionHistory, 
"AboutWindow");
 
-       BString text("");
-       if (fAboutView->InfoView()->TextLength() > 0)
-               text << "\n\n";
-
-       text << versionHistory << "\n";
-       for (int32 i = 0; history[i]; i++)
-               text << "    " << history[i] << "\n";
-
-       fAboutView->InfoView()->Insert(text.String());
+       AddText(versionHistory, history);
 }
 
 
@@ -575,6 +542,39 @@ BAboutWindow::AddExtraInfo(const char* extraInfo)
 }
 
 
+void
+BAboutWindow::AddText(const char* header, const char** contents)
+{
+       BTextView* infoView = fAboutView->InfoView();
+       int32 textLength = infoView->TextLength();
+       BString text("");
+
+       if (textLength > 0) {
+               text << "\n\n";
+               textLength += 2;
+       }
+
+       const char* indent = "";
+       if (header != NULL) {
+               indent = "    ";
+               text << header;
+       }
+
+       if (contents != NULL) {
+               text << "\n";
+               for (int32 i = 0; contents[i]; i++)
+                       text << indent << contents[i] << "\n";
+       }
+
+       infoView->Insert(text.String());
+
+       if (contents != NULL && header != NULL) {
+               infoView->SetFontAndColor(textLength, textLength + 
strlen(header),
+                       be_bold_font);
+       }
+}
+
+
 const char*
 BAboutWindow::Name()
 {


Other related posts:

  • » [haiku-commits] haiku: hrev45649 - src/kits/shared headers/private/shared - pulkomandy