AboutWindow.cpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. * Copyright 2010-2011, Pier Luigi Fiorini. All rights reserved.
  3. * Copyright 2007-2009, Haiku, Inc. All rights reserved.
  4. * Distributed under the terms of the MIT License.
  5. *
  6. * Authors:
  7. * Pier Luigi Fiorini, pierluigi.fiorini@gmail.com
  8. * Ryan Leavengood, leavengood@gmail.com
  9. */
  10. #include <Alert.h>
  11. #include <Catalog.h>
  12. #include <Font.h>
  13. #include <String.h>
  14. #include <TextView.h>
  15. #include "AboutWindow.h"
  16. #undef B_TRANSLATION_CONTEXT
  17. #define B_TRANSLATION_CONTEXT "About window"
  18. AboutWindow::AboutWindow(const char* appName, const char** holders,
  19. const char** authors, const char* extraInfo)
  20. {
  21. fAppName = new BString(appName);
  22. // Build the text to display
  23. int32 i;
  24. BString text(appName);
  25. text << "\n\n";
  26. for (i = 0; holders[i]; i++)
  27. text << B_TRANSLATE("Copyright " B_UTF8_COPYRIGHT " ") << holders[i]
  28. << "\n";
  29. text << B_TRANSLATE("\nWritten by:\n");
  30. for (int32 i = 0; authors[i]; i++) {
  31. text << " " << authors[i] << "\n";
  32. }
  33. // The extra information is optional
  34. if (extraInfo != NULL)
  35. text << "\n" << extraInfo << "\n";
  36. fText = new BString(text);
  37. }
  38. AboutWindow::~AboutWindow()
  39. {
  40. delete fText;
  41. delete fAppName;
  42. }
  43. void
  44. AboutWindow::Show()
  45. {
  46. BAlert* alert = new BAlert(B_TRANSLATE("About" B_UTF8_ELLIPSIS),
  47. fText->String(), B_TRANSLATE("Close"));
  48. BTextView* view = alert->TextView();
  49. BFont font;
  50. view->SetStylable(true);
  51. view->GetFont(&font);
  52. font.SetFace(B_BOLD_FACE);
  53. font.SetSize(font.Size() * 1.7f);
  54. view->SetFontAndColor(0, fAppName->Length(), &font);
  55. alert->Go();
  56. }