コード例 #1
0
ファイル: Utils.cpp プロジェクト: Htallon/QtHandles
QFont computeFont (const typename T::properties& props, int height)
{
  QFont f (fromStdString (props.get_fontname ()));

  static std::map<std::string, QFont::Weight> weightMap;
  static std::map<std::string, QFont::Style> angleMap;
  static bool mapsInitialized = false;

  if (! mapsInitialized)
    {
      weightMap[std::string ("normal")] = QFont::Normal;
      weightMap[std::string ("light")] = QFont::Light;
      weightMap[std::string ("demi")] = QFont::DemiBold;
      weightMap[std::string ("bold")] = QFont::Normal;

      angleMap[std::string ("normal")] = QFont::StyleNormal;
      angleMap[std::string ("italic")] = QFont::StyleItalic;
      angleMap[std::string ("oblique")] = QFont::StyleOblique;

      mapsInitialized = true;
    }

  f.setPointSizeF (props.get_fontsize_points (height));
  f.setWeight (weightMap[props.get_fontweight ()]);
  f.setStyle (angleMap[props.get_fontangle ()]);

  return f;
}
コード例 #2
0
void ReportHandler_message_handler(const std::string &str) {
    ReportHandler::warning(fromStdString(str));
}
コード例 #3
0
ファイル: Settings.cpp プロジェクト: bearxiong99/CodeLibrary
Settings::Settings(int argc, char **argv)
{
  try {
    TCLAP::CmdLine cmd("", ' ', VERSION_STRING, true);
    std::string    fmtrMsg = std::string("Output formatter type: ");
    
    /* Constraint definitions. */
    FormatConstraint         allowedFmt(nullStrVec);
    YearConstraint           allowedYear(nullIntVec);
    std::vector<std::string> allowedGroupsVec;
    std::vector<std::string> allowedIncrsVec;
    std::vector<std::string> allowedFmatrsVec;
    
    /* Output group values. */
    allowedGroupsVec.push_back("basic");
    allowedGroupsVec.push_back("struct");
    allowedGroupsVec.push_back("doxygen");
    allowedGroupsVec.push_back("all");
    TCLAP::ValuesConstraint<std::string> allowedGroups(allowedGroupsVec);
    
    /* Incrementation constraint values. */
    allowedIncrsVec.push_back("simple");
    allowedIncrsVec.push_back("date");
    allowedIncrsVec.push_back("months");
    allowedIncrsVec.push_back("years");
    TCLAP::ValuesConstraint<std::string> allowedIncrs(allowedIncrsVec);
    
    /* Formatter constraint values. */
    {
      size_t cnt = FormatterFactory::size();

      for (FormatterFnMap::iterator it = FormatterFactory::begin();
           it != FormatterFactory::end();
           ++it)
      {
        allowedFmatrsVec.push_back(it->first);
        fmtrMsg += it->first + " = "
            + FormatterFactory::nameForFormatter(it->first);

        if (cnt > 1) {
          fmtrMsg += ", ";
        }
      }
    }
    TCLAP::ValuesConstraint<std::string> allowedFmtrs(allowedFmatrsVec);
    
    /* Arguments. */
    StringOpt fileName("o",
                       "output",
                       "File containing version information.",
                       false,
                       "",
                       "string");
    StringOpt verFmt("f",
                     "format",
                     "Version number format string.",
                     false,
                     "*.*.+.*",
                     &allowedFmt);
    IntOpt baseYear("y",
                    "base-year",
                    "The year the project was started.",
                    false,
                    0,
                    &allowedYear);
    StringOpt incrType("i",
                       "increment",
                       "Type of increment used.",
                       false,
                       "simple",
                       &allowedIncrs);
    TCLAP::SwitchArg overFlow("s",
                              "overflow",
                              "Perform overflow checking and shifting.",
                              false);
    TCLAP::SwitchArg verbose("v",
                             "verbose",
                             "Verbose output.",
                             false);
    TCLAP::SwitchArg createFile("c",
                                "create",
                                "Create the output file if it does not exist.",
                                false);
    StringOpt formatter("t",
                        "formatter",
                        fmtrMsg,
                        true,
                        "",
                        &allowedFmtrs);
    TCLAP::MultiArg<std::string> groups("g",
                                        "groups",
                                        "Output groups generated.",
                                        false,
                                        &allowedGroups);
    StringOpt outPref("p",
                      "prefix",
                      "String to prepend to symbols created by the formatter.",
                      false,
                      "",
                      "string");
    
    /* Add them in reverse alphabetic order. */
    cmd.add(baseYear);          // y
    cmd.add(verbose);           // v
    cmd.add(formatter);         // t
    cmd.add(overFlow);          // s
    cmd.add(outPref);           // p
    cmd.add(fileName);          // o
    cmd.add(incrType);          // i
    cmd.add(groups);            // g
    cmd.add(verFmt);            // f
    cmd.add(createFile);        // c
    cmd.parse(argc, argv);
    
    /* Fill the static vector here. */
    m_static.fill(nullInitial, 4);
    
    /* Extract the options. */
    m_filePath     = fromStdString(fileName.getValue());
    m_format       = fromStdString(verFmt.getValue());
    m_formatter    = fromStdString(formatter.getValue());
    m_baseYear     = baseYear.getValue();
    m_overflow     = overFlow.getValue();
    m_verbose      = verbose.getValue();
    m_createFile   = createFile.getValue();
    m_groups       = groups.getValue();
    m_outputPrefix = fromStdString(outPref.getValue());

    /* Extract the incrementation type. */
    if (incrType.getValue().compare("date") == 0) {
      m_incrType = BuildByDate;
    } else if (incrType.getValue().compare("months") == 0) {
      m_incrType = BuildByMonths;
    } else if (incrType.getValue().compare("years") == 0) {
      m_incrType = BuildByYears;
    } else {
      m_incrType = BuildSimple;
    }
    
    /* Are we to use stdout? */
    if (m_filePath.isNull() || m_filePath.length() == 0)
    {  
      m_useStdOut = true;
    } else {
      m_useStdOut = false;
    }
  }
  
  catch (TCLAP::ArgException &e) {
    std::cerr << "Error: " << e.error()
              << " for arg " << e.argId()
              << std::endl;
  }
}                               // Settings::Settings()
コード例 #4
0
ファイル: kabcconversion.cpp プロジェクト: maxyz/libkolab
KABC::Addressee toKABC(const Kolab::Contact &contact)
{
  KABC::Addressee addressee;
  addressee.setUid(fromStdString(contact.uid()));
  addressee.setCategories(toStringList(contact.categories()));
  //addressee.setName(fromStdString(contact.name()));//This one is only for compatiblity (and results in a non-existing name property)
  addressee.setFormattedName(fromStdString(contact.name())); //This on corresponds to fn
  
  const Kolab::NameComponents &nc = contact.nameComponents();
  if (!nc.surnames().empty()) {
      addressee.setFamilyName(fromStdString(nc.surnames().front()));
  }
  if (!nc.given().empty()) {
      addressee.setGivenName(fromStdString(nc.given().front()));
  }
  if (!nc.additional().empty()) {
      addressee.setAdditionalName(fromStdString(nc.additional().front()));
  }
  if (!nc.prefixes().empty()) {
      addressee.setPrefix(fromStdString(nc.prefixes().front()));
  }
  if (!nc.suffixes().empty()) {
      addressee.setSuffix(fromStdString(nc.suffixes().front()));
  }
  
  addressee.setNote(fromStdString(contact.note()));
  
  addressee.setSecrecy(KABC::Secrecy::Public); //We don't have any privacy setting in xCard
  
  
  QString preferredEmail;
  
  if (!contact.emailAddresses().empty()) {
      QStringList emails;
      foreach( const Kolab::Email &email, contact.emailAddresses()) {
          emails << fromStdString(email.address());
          const QString types = emailTypesToStringList(email.types());
          if (!types.isEmpty()) {
              addressee.insertCustom(QLatin1String("KOLAB"), QString::fromLatin1("EmailTypes%1").arg(fromStdString(email.address())), types);
          }
      }
      addressee.setEmails(emails);
      if ((contact.emailAddressPreferredIndex() >= 0) && (contact.emailAddressPreferredIndex() < static_cast<int>(contact.emailAddresses().size()))) {
          preferredEmail = fromStdString(contact.emailAddresses().at(contact.emailAddressPreferredIndex()).address());
      } else {
          preferredEmail = fromStdString(contact.emailAddresses().at(0).address());
      }
      addressee.insertEmail(preferredEmail, true);
  }